JOIN US
Object oriented programming Java
1. Break statement in switch case
a.prevents from fallthrough
b.causes an exit from innermost loop
c.both a and b
d.none
Answer: C
2. The keyword 'this' is used
a. As reference to current object
b. Explicit constructor invocation
c. In open recursion
d. All the above
Answer: D
3. When does method overloading is determined?
a) At run time
b) At compile time
c) At coding time
d) At execution time
Answer: b
4. When Overloading does not occur?
a) More than one method with same name but different method signature and
different number or type of parameters
b) More than one method with same name, same signature but different number
of signature
c) More than one method with same name, same signature, same number of
parameters but different type
d) More than one method with same name, same number of parameters and type
but different signature
Answer: d
5. Method overriding is combination of inheritance and polymorphism?
a) True
b) false
Answer: a
6. What is the stored in the object obj in following lines of Java code?
box obj;
a) Memory address of allocated memory of object
b) NULL
c) Any arbitrary pointer
d) Garbage
Answer: b
7. Which of these keywords is used to make a class?
a) class
b) struct
c) int
d) none of the mentioned
Answer: a
8. Which of the following is a valid declaration of an object of class
Box?
a) Box obj = new Box();
b) Box obj = new Box;
c) obj = new Box();
d) new Box obj;
Answer: a
9. Which of these operators is used to allocate memory for an object?
a) malloc
b) alloc
c) new
d) give
Answer: c
10. Which of these statement is incorrect?
a) Every class must contain a main() method
b) Applets do not require a main() method at all
c) There can be only one main() method in a program
d) main() method must be made public
Answer: a
11. What will be the output of the following Java program?
-
class main_class
-
{
-
public static void main(String args[])
-
{
-
int x = 9;
-
if (x == 9)
-
{
-
int x = 8;
-
System.out.println(x);
-
}
-
}
-
}
a) 9
b) 8
c) Compilation error
d) Runtime error
Answer: c
12. Which of the following statements is correct?
a) Public method is accessible to all other classes in the hierarchy
b) Public method is accessible only to subclasses of its parent class
c) Public method can only be called by object of its class
d) Public method can be accessed by calling object of the public
class
Answer: a
13. What will be the output of the following Java program?
-
class box
-
{
-
int width;
-
int height;
-
int length;
-
}
-
class mainclass
-
{
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.width = 10;
-
obj.height = 2;
-
obj.length = 10;
-
int y = obj.width * obj.height * obj.length;
-
System.out.print(y);
-
}
-
}
a) 12
b) 200
c) 400
d) 100
Answer: b
14. What will be the output of the following Java program?
-
class box
-
{
-
int width;
-
int height;
-
int length;
-
}
-
class mainclass
-
{
-
public static void main(String args[])
-
{
-
box obj1 = new box();
-
box obj2 = new box();
-
obj1.height = 1;
-
obj1.length = 2;
-
obj1.width = 1;
-
obj2 = obj1;
-
System.out.println(obj2.height);
-
}
-
}
a) 1
b) 2
c) Runtime error
d) Garbage value
Answer: a
15. What will be the output of the following Java program?
-
class box
-
{
-
int width;
-
int height;
-
int length;
-
}
-
class mainclass
-
{
-
public static void main(String args[])
-
{
-
box obj = new box();
-
System.out.println(obj);
-
}
-
}
a) 0
b) 1
c) Runtime error
d)classname@hashcode
in hexadecimal form
Answer: d
16. What is the process of defining two or more methods within same class
that have same name but different parameters declaration?
a) method overloading
b) method overriding
c) method hiding
d) none of the mentioned
Answer: a
17. Which of these can be overloaded?
a) Methods
b) Constructors
c) All of the mentioned
d) None of the mentioned
Answer: c
18. What will be the output of the following Java code?
-
class San
-
{
-
public void m1 (int i,float f)
-
{
-
System.out.println(" int float method");
-
}
-
-
public void m1(float f,int i);
-
{
-
System.out.println("float int method");
-
}
-
-
public static void main(String[]args)
-
{
-
San s=new San();
-
s.m1(20,20);
-
}
-
}
a) int float method
b) float int method
c) compile time error
d) run time error
Answer: c
19. What will be the output of the following Java code?
-
class overload
-
{
-
int x;
-
int y;
-
void add(int a)
-
{
-
x = a + 1;
-
}
-
void add(int a, int b)
-
{
-
x = a + 2;
-
}
-
}
-
class Overload_methods
-
{
-
public static void main(String args[])
-
{
-
overload obj = new overload();
-
int a = 0;
-
obj.add(6);
-
System.out.println(obj.x);
-
}
-
}
a) 5
b) 6
c) 7
d) 8
Answer: c
20. What will be the output of the following Java code?
-
class overload
-
{
-
int x;
-
int y;
-
void add(int a)
-
{
-
x = a + 1;
-
}
-
void add(int a , int b)
-
{
-
x = a + 2;
-
}
-
}
-
class Overload_methods
-
{
-
public static void main(String args[])
-
{
-
overload obj = new overload();
-
int a = 0;
-
obj.add(6, 7);
-
System.out.println(obj.x);
-
}
-
}
a) 6
b) 7
c) 8
d) 9
Answer: c
21. What will be the output of the following Java code?
-
class overload {
-
int x;
-
double y;
-
void add(int a , int b)
-
{
-
x = a + b;
-
}
-
void add(double c , double d)
-
{
-
y = c + d;
-
}
-
overload()
-
{
-
this.x = 0;
-
this.y = 0;
-
}
-
}
-
class Overload_methods {
-
public static void main(String args[])
-
{
-
overload obj = new overload();
-
int a = 2;
-
double b = 3.2;
-
obj.add(a, a);
-
obj.add(b, b);
-
System.out.println(obj.x + " " + obj.y);
-
}
-
}
a) 6 6
b) 6.4 6.4
c) 6.4 6
d) 4 6.4
Answer: d
22. What will be the output of the following Java code?
-
class test
-
{
-
int a;
-
int b;
-
void meth(int i , int j)
-
{
-
i *= 2;
-
j /= 2;
-
}
-
}
-
class Output
-
{
-
public static void main(String args[])
-
{
-
test obj = new test();
-
int a = 10;
-
int b = 20;
-
obj.meth(a , b);
-
System.out.println(a + " " + b);
-
}
-
}
a) 10 20
b) 20 10
c) 20 40
d) 40 20
Answer: a
23. What will be the output of the following Java code?
-
class test
-
{
-
int a;
-
int b;
-
test(int i, int j)
-
{
-
a = i;
-
b = j;
-
}
-
void meth(test o)
-
{
-
o.a *= 2;
-
O.b /= 2;
-
}
-
}
-
class Output
-
{
-
public static void main(String args[])
-
{
-
test obj = new test(10 , 20);
-
obj.meth(obj);
-
System.out.println(obj.a + " " + obj.b);
-
}
-
}
a) 10 20
b) 20 10
c) 20 40
d) 40 20
Answer: b
24. Which of these is the method which is executed first before execution
of any other thing takes place in a program?
a) main method
b) finalize method
c) static method
d) private method
Answer: c
25. What is the process of defining more than one method in a class
differentiated by parameters?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned
Answer: b
26. Which of these can be used to differentiate two or more methods having
the same name?
a) Parameters data type
b) Number of parameters
c) Return type of method
d) All of the mentioned
Answer: d
27. Which of these data type can be used for a method having a return
statement in it?
a) void
b) int
c) float
d) both int and float
Answer: d
28. Which of these statement is incorrect?
a) Two or more methods with same name can be differentiated on the basis of
their parameters data type
b) Two or more method having same name can be differentiated on basis of
number of parameters
c) Any already defined method in java library can be defined again in the
program with different data type of parameters
d) If a method is returning a value the calling statement must have a
variable to store that value
Answer: d
29. What will be the output of the following Java program?
-
class box
-
{
-
int width;
-
int height;
-
int length;
-
int volume;
-
void volume(int height, int length, int width)
-
{
-
volume = width * height * length;
-
}
-
}
-
class Prameterized_method{
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.height = 1;
-
obj.length = 5;
-
obj.width = 5;
-
obj.volume(3, 2, 1);
-
System.out.println(obj.volume);
-
}
-
}
a) 0
b) 1
c) 6
d) 25
Answer: c
30. What will be the output of the following Java program?
-
class equality
-
{
-
int x;
-
int y;
-
boolean isequal()
-
{
-
return(x == y);
-
}
-
}
-
class Output
-
{
-
public static void main(String args[])
-
{
-
equality obj = new equality();
-
obj.x = 5;
-
obj.y = 5;
-
System.out.println(obj.isequal);
-
}
-
}
a) false
b) true
c) 0
d) 1
Answer: b
31. What will be the output of the following Java program?
-
class box
-
{
-
int width;
-
int height;
-
int length;
-
int volume;
-
void volume()
-
{
-
volume = width * height * length;
-
}
-
void volume(int x)
-
{
-
volume = x;
-
}
-
}
-
class Output
-
{
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.height = 1;
-
obj.length = 5;
-
obj.width = 5;
-
obj.volume(5);
-
System.out.println(obj.volume);
-
}
-
}
a) 0
b) 5
c) 25
d) 26
Answer: b
32. What will be the output of the following Java program?
-
class Output
-
{
-
static void main(String args[])
-
{
-
int x , y = 1;
-
x = 10;
-
if(x != 10 && x / 0 == 0)
-
System.out.println(y);
-
else
-
System.out.println(++y);
-
}
-
}
a) 1
b) 2
c) Runtime Error
d) Compilation Error
Answer: d
33. What will be the output of the following Java program?
-
class area
-
{
-
int width;
-
int length;
-
int height;
-
area()
-
{
-
width = 5;
-
length = 6;
-
height = 1;
-
}
-
void volume()
-
{
-
volume = width * height * length;
-
}
-
}
-
class cons_method
-
{
-
public static void main(String args[])
-
{
-
area obj = new area();
-
obj.volume();
-
System.out.println(obj.volume);
-
}
-
}
a) 0
b) 1
c) 25
d) 30
Answer: d
34. Which of these keywords is used to prevent content of a variable from
being modified?
a) final
b) last
c) constant
d) static
Answer: a
35. Which of these cannot be declared static?
a) class
b) object
c) variable
d) method
Answer: b
36. Which of the following statements are incorrect?
a) static methods can call other static methods only
b) static methods must only access static data
c) static methods can not refer to this or super in any way
d) when object of class is declared, each object contains its own copy of
static variables
Answer: d
37. Which of the following statements are incorrect?
a) Variables declared as final occupy memory
b) final variable must be initialized at the time of declaration
c) Arrays in java are implemented as an object
d) All arrays contain an attribute-length which contains the number of
elements stored in the array
Answer: a
38. Which of these methods must be made static?
a) main()
b) delete()
c) run()
d) finalize()
Answer: a
39. What will be the output of the following Java program?
-
class access
-
{
-
public int x;
-
static int y;
-
void cal(int a, int b)
-
{
-
x += a ;
-
y += b;
-
}
-
}
-
class static_specifier
-
{
-
public static void main(String args[])
-
{
-
access obj1 = new access();
-
access obj2 = new access();
-
obj1.x = 0;
-
obj1.y = 0;
-
obj1.cal(1, 2);
-
obj2.x = 0;
-
obj2.cal(2, 3);
-
System.out.println(obj1.x + " " + obj2.y);
-
}
-
}
a) 1 2
b) 2 3
c) 3 2
d) 1 5
Answer: d
40. What will be the output of the following Java program?
-
class access
-
{
-
static int x;
-
void increment()
-
{
-
x++;
-
}
-
}
-
class static_use
-
{
-
public static void main(String args[])
-
{
-
access obj1 = new access();
-
access obj2 = new access();
-
obj1.x = 0;
-
obj1.increment();
-
obj2.increment();
-
System.out.println(obj1.x + " " + obj2.x);
-
}
-
}
a) 1 2
b) 1 1
c) 2 2
d) Compilation Error
Answer: c
41. What will be the output of the following Java program?
-
class static_out
-
{
-
static int x;
-
static int y;
-
void add(int a , int b)
-
{
-
x = a + b;
-
y = x + b;
-
}
-
}
-
class static_use
-
{
-
public static void main(String args[])
-
{
-
static_out obj1 = new static_out();
-
static_out obj2 = new static_out();
-
int a = 2;
-
obj1.add(a, a + 1);
-
obj2.add(5, a);
-
System.out.println(obj1.x + " " + obj2.y);
-
}
-
}
a) 7 7
b) 6 6
c) 7 9
d) 9 7
Answer: c
42. What will be the output of the following Java program?
-
class Output
-
{
-
public static void main(String args[])
-
{
-
int arr[] = {1, 2, 3, 4, 5};
-
for ( int i = 0; i < arr.length - 2; ++i)
-
System.out.println(arr[i] + " ");
-
}
-
}
a) 1 2
b) 1 2 3
c) 1 2 3 4
d) 1 2 3 4 5
Answer: b
43. What will be the output of the following Java program?
-
class Output
-
{
-
public static void main(String args[])
-
{
-
int a1[] = new int[10];
-
int a2[] = {1, 2, 3, 4, 5};
-
System.out.println(a1.length + " " + a2.length);
-
}
-
}
a) 10 5
b) 5 10
c) 0 10
d) 0 5
Answer: a
44. What is the return type of a method that does not return any
value?
a) int
b) float
c) void
d) double
Answer: c
45. What is the process of defining more than one method in a class
differentiated by method signature?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned
Answer: b
46. Which of the following is a method having same name as that of it’s
class?
a) finalize
b) delete
c) class
d) constructor
Answer: d
47. Which method can be defined only once in a program?
a) main method
b) finalize method
c) static method
d) private method
Answer: a
48. Which of this statement is incorrect?
a) All object of a class are allotted memory for the all the variables
defined in the class
b) If a function is defined public it can be accessed by object of other
class by inheritation
c) main() method must be made public
d) All object of a class are allotted memory for the methods defined in the
class
Answer: d
49. What will be the output of the following Java program?
-
class box
-
{
-
int width;
-
int height;
-
int length;
-
int volume;
-
void volume(int height, int length, int width)
-
{
-
volume = width*height*length;
-
}
-
}
-
class Prameterized_method
-
{
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.height = 1;
-
obj.length = 5;
-
obj.width = 5;
-
obj.volume(3,2,1);
-
System.out.println(obj.volume);
-
}
-
}
a) 0
b) 1
c) 6
d) 25
Answer: c
50. What will be the output of the following Java program?
-
class equality
-
{
-
int x;
-
int y;
-
boolean isequal()
-
{
-
return(x == y);
-
}
-
}
-
class Output
-
{
-
public static void main(String args[])
-
{
-
equality obj = new equality();
-
obj.x = 5;
-
obj.y = 5;
-
System.out.println(obj.isequal());
-
}
-
}
a) false
b) true
c) 0
d) 1
Answer: b
51. What will be the output of the following Java program?
-
class box
-
{
-
int width;
-
int height;
-
int length;
-
int volume;
-
void volume()
-
{
-
volume = width*height*length;
-
}
-
}
-
class Output
-
{
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.height = 1;
-
obj.length = 5;
-
obj.width = 5;
-
obj.volume();
-
System.out.println(obj.volume);
-
}
-
}
a) 0
b) 1
c) 25
d) 26
Answer: c
52. In the following Java code, which call to sum() method is appropriate?
-
class Output
-
{
-
-
public static int sum(int ...x)
-
{
-
return;
-
}
-
static void main(String args[])
-
{
-
sum(10);
-
sum(10,20);
-
sum(10,20,30);
-
sum(10,20,30,40);
-
}
-
}
a) only sum(10)
b) only sum(10,20)
c) only sum(10) & sum(10,20)
d) all of the mentioned
Answer: d
53. What will be the output of the following Java program?
-
class area
-
{
-
int width;
-
int length;
-
int volume;
-
area()
-
{
-
width=5;
-
length=6;
-
}
-
void volume()
-
{
-
volume = width*length*height;
-
}
-
}
-
class cons_method
-
{
-
public static void main(String args[])
-
{
-
area obj = new area();
-
obj.volume();
-
System.out.println(obj.volume);
-
}
-
}
a) 0
b) 1
c) 30
d) error
Answer: d
54. What is an array of objects?
a) An array of instances of class represented by single name
b) An array of instances of class represented by more than one name
c) An array of instances which have more than 2 instances
d) An array of instances which have different types
Answer: a
55. Which among the following is a mandatory condition for array of
objects?
a) All the objects should be of different class
b) All the objects should be of same program classes
c) All the objects should be of same class
d) All the objects should have different data
Answer: c
56. What is the type of elements of array of objects?
a) Class
b) Void
c) String
d) Null
Answer: a
57. If array of objects is declared as given below, which is the limitation on objects?
Class_name arrayName[size];
a) The objects will have same values
b) The objects will not be initialized individually
c) The objects can never be initialized
d) The objects will have same data
Answer: b
58. Which is the condition that must be followed if the array of objects is
declared without initialization, only with size of array?
a) The class should have separate constructor for each object
b) The class must have no constructors
c) The class should not have any member function
d) The class must have a default or zero argument constructor
Answer: d
59. When are the array of objects without any initialization useful?
a) When object data is not required just after the declaration
b) When initialization of object data is to be made by the compiler
c) When object data doesn’t matter in the program
d) When the object should contain garbage data
Answer: a
60. If constructor arguments are passed to objects of array then
____________ if the constructors are overloaded.
a) It is mandatory to pass same number of arguments to all the
objects
b) It is mandatory to pass same type of arguments to all the objects
c) It is not mandatory to call same constructor for all the objects
d) It is mandatory to call same constructor for all the constructors
Answer: c
61. How the objects of array can be denoted?
a) Indices
b) Name
c) Random numbers
d) Alphabets
Answer: a
62. The objects in an object array _______________________
a) Can be created without use of constructor
b) Can be created without calling default constructor
c) Can’t be created with use of constructor
d) Can’t be created without calling default constructor
Answer: b
63. The Object array is created in _____________________
a) Heap memory
b) Stack memory
c) HDD
d) ROM
Answer: a
64. If an array of objects is of size 10 and a data value have to be
retrieved from 5th object then ________________ syntax should be used.
a) Array_Name[4].data_variable_name;
b) Data_Type Array_Name[4].data_variable_name;
c) Array_Name[4].data_variable_name.value;
d) Array_Name[4].data_variable_name(value);
Answer: a
65. Can we have two dimensional object array?
a) Yes, always
b) Yes, only if primitive type array
c) No, since two indices are impossible
d) No, never
Answer: a
66. From which index does the array of objects start?
a) 0
b) 1
c) 2
d) 3
Answer: a
67. Two dimensional array can’t be initialized with the declaration.
a) True
b) False
Answer: b
68. Is an array of characters always a string?
a) Yes, always
b) Yes, if each character is terminated by null
c) No, since each character is terminated by null
d) No, never
Answer: d
69. In which of the following way(s) can the object be returned from a
function?
a) Can only be returned by value
b) Can only be returned by reference
c) Can be returned either by value or reference
d) Can neither be returned by value nor by reference
Answer: c
70. Whenever an object is returned by value ____________________
a) A temporary object is created
b) Temporary object is not created
c) Temporary object may or may not be created
d) New permanent object is created
Answer: a
71. Where the temporary objects (created while return by value) are
created?
a) Outside the function scope
b) Within the function
c) Inside the main function
d) Inside the calling function
Answer: b
72. Which is the correct syntax for returning an object by value?
a) void functionName ( ){ }
b) object functionName( ) { }
c) class object functionName( ) { }
d) ClassName functionName ( ){ }
Answer: d
73. If an object is declared inside the function then ____________________
outside the function.
a) It can be returned by reference
b) It can’t be returned by reference
c) It can be returned by address
d) It can’t be returned at all
Answer: b
74. How many independent objects can be returned at same time from a
function?
a) 1
b) 2
c) 3
d) 4
Answer: a
75. Which error will be produced if a local object is returned by reference
outside a function?
a) Out of memory error
b) Run time error
c) Compile time error
d) No error
Answer: c
76. Which of these class is superclass of every class in Java?
a) String class
b) Object class
c) Abstract class
d) ArrayList class
Answer: b
77. Which of these keywords can be used to prevent inheritance of a
class?
a) super
b) constant
c) class
d) final
Answer: d
78. Which of these keywords cannot be used for a class which has been
declared final?
a) abstract
b) extends
c) abstract and extends
d) none of the mentioned
Answer: a
79. Which of these class relies upon its subclasses for complete
implementation of its methods?
a) Object class
b) abstract class
c) ArrayList class
d) None of the mentioned
Answer: b
80. What will be the output of the following Java program?
-
abstract class A
-
{
-
int i;
-
abstract void display();
-
}
-
class B extends A
-
{
-
int j;
-
void display()
-
{
-
System.out.println(j);
-
}
-
}
-
class Abstract_demo
-
{
-
public static void main(String args[])
-
{
-
B obj = new B();
-
obj.j=2;
-
obj.display();
-
}
-
}
a) 0
b) 2
c) Runtime Error
d) Compilation Error
Answer: b
81. What will be the output of the following Java program?
-
class A
-
{
-
int i;
-
int j;
-
A()
-
{
-
i = 1;
-
j = 2;
-
}
-
}
-
class Output
-
{
-
public static void main(String args[])
-
{
-
A obj1 = new A();
-
A obj2 = new A();
-
System.out.print(obj1.equals(obj2));
-
}
-
}
a) false
b) true
c) 1
d) Compilation Error
Answer: a
82. What will be the output of the following Java code?
-
class Output
-
{
-
public static void main(String args[])
-
{
-
Object obj = new Object();
-
System.out.print(obj.getclass());
-
}
-
}
a) Object
b) class Object
c) class java.lang.Object
d) Compilation Error
Answer: c
83. What will be the output of the following Java code?
-
class A
-
{
-
int i;
-
int j;
-
A()
-
{
-
i = 1;
-
j = 2;
-
}
-
}
-
class Output
-
{
-
public static void main(String args[])
-
{
-
A obj1 = new A();
-
System.out.print(obj1.toString());
-
}
-
}
a) true
b) false
c) String associated with obj1
d) Compilation Error
Answer: c
84. What is the new operator?
a) Allocates memory for an object or array
b) Allocates memory for an object or array and returns a particular
pointer
c) Used as return type when an object is created
d) Used to declare any new thing in a program
Answer: b
85. The new operator _____________
a) Can allocate reference types too
b) Doesn’t allocate reference types
c) Can allocate reference to objects
d) Doesn’t allocate any data
Answer: b
86. Which among the following is true?
a) New operator can’t allocate functions but pointer to functions can be
allocated
b) New operator can allocate functions as well as pointer to
functions
c) New operator can allocate any type of functions
d) New operator is not applicable with functions allocation
Answer: a
87. Which among the following is added in grammar of new operator?
a) Finalize
b) Arg
c) Initializer
d) Allocator
Answer: c
88. Initializers __________________
a) Are used for specifying arrays
b) Are used to defined multidimensional arrays
c) Can’t be specified for arrays
d) Can’t be specified for any data
Answer: c
89. The objects allocated using new operator ________________
a) Are destroyed when they go out of scope
b) Are not destroyed even if they go out of scope
c) Are destroyed anytime
d) Are not destroyed throughout the program execution
Answer: b
90. The new operator _________________
a) Invokes function operator new
b) Doesn’t invoke function operator new
c) Invokes function operator only if required
d) Can’t invoke function operator new implicitly
Answer: a
91. If a new operator is defined for a class and still global new operator
have to be used, which operator should be used with the keyword new?
a) Colon
b) Arrow
c) Dot
d) Scope resolution
Answer: d
0 Comments
Please feel free to comment. Being diploma students We are always ready to help diploma Students