Question 1 of 25
Hints left: 3
Q1
What is method overriding in Java?
Q2
What will be the result of compiling and running the following code: public class Test{ public static void main(String... args) throws Exception{ Integer i = 34; int l = 34; if(i.equals(l)){ System.out.println("true"); }else{ System.out.println("false"); } } }
Q3
What is method hiding in Java?
Q4
What will be the output? public class Test{ public static void main(String args[]){ int i = 1; do{ i--; }while(i > 2); System.out.println(i); } }
Q5
What all gets printed when the following program is compiled and run. public class Test{ public static void main(String args[]){ int i, j=1; i = (j>1)?2:1; switch(i){ case 0: System.out.println(0); break; case 1: System.out.println(1); case 2: System.out.println(2); break; case 3: System.out.println(3); break; } } }
Q6
What happens when a subclass tries to override a final method from the superclass in Java?
Q7
Which of the following for loops will be an infinite loop?
Q8
In method overriding, which keyword is used in the child class to indicate that a method is intended to override a superclass method?
Q9
What is the purpose of method overloading in Java?
Q10
What all gets printed when the following program is compiled and run? public class Test{ public static void main(String args[]){ int i=0, j=2; do{ i=++i; j--; }while(j>0); System.out.println(i); } }
Q11
Which of these is used to access a member of class before object of that class is created?
Q12
Which of these access specifiers must be used for main() method?
Q13
What is the process by which we can control what parts of a program can access the members of a class?
Q14
Which of these is used as a default for a member of a class if no access specifier is used for it?
Q15
public class Test{ public static void main(String [] args){ int x = 0; // insert code here do{ } while(x++ < y); System.out.println(x); } } Which option, inserted at line 4, produces the output 12?
Q16
Choose the correct statement in context of the following program code. public class Test{ public static void main(String[] args){ double sum = 0; for(double d = 0; d < 10;){ d += 0.1; sum += sum + d; } } }
Q17
What will be the output of the following Java code? class access { public int x; private int y; void cal(int a, int b) { x = a + 1; y = b; } void print() { System.out.println(" " + y); } } public class access_specifier { public static void main(String args[]) { access obj = new access(); obj.cal(2, 3); System.out.println(obj.x); obj.print(); } }
Q18
What will be the result? int i = 10; while(i++ <= 10){ i++; } System.out.print(i);
Q19
What is the value of a[1] after the following code is executed? int[] a = {0, 2, 4, 1, 3}; for(int i = 0; i < a.length; i++) a[i] = a[(a[i] + 3) % a.length];
Q20
Which of the following statements are incorrect?
Q21
What will be the output of the following Java code? class static_out { static int x; static int y; void add(int a, int b) { x = a + b; y = x + b; } } public 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); } }
Q22
What will be the result of the following code? public class Test{ static public void main(String args[]){ //line 2 int i, j; for(i=0; i<3; i++){ for(j=1; j<4; j++){ i%=j; System.out.println(j); } } } }
Q23
Which of these access specifier must be used for class so that it can be inherited by another subclass?
Q24
In method overloading, what must be different between the overloaded methods in the same class?
Q25
What will be the output of the following Java code? class access { public int x; private int y; void cal(int a, int b) { x = a + 1; y = b; } } public class access_specifier { public static void main(String args[]) { access obj = new access(); obj.cal(2, 3); System.out.println(obj.x + " " + obj.y); } }