Consider the code:
class A { A() { System.out.println("A"); } }
class B extends A { B() { super(); System.out.println("B"); } }
What will be printed when 'new B()' is executed?
Q.42Easy
Which access modifier allows a member to be accessed only within the same class?
Q.43Medium
What will happen if you try to override a final method in a child class?
Q.44Medium
Which statement about 'this' keyword is correct?
Q.45Medium
Consider:
interface I1 { void method(); }
interface I2 { void method(); }
class C implements I1, I2 { public void method() { System.out.println("Method"); } }
What will be the behavior?
Advertisement
Q.46Medium
What is method overloading?
Q.47Medium
Which of the following is true about abstract classes?
Q.48Easy
Which concept best describes the relationship between Parent and Child classes in 'class Child extends Parent'?
Q.49Hard
What is the output of this code?
class A { int x = 10; }
class B extends A { int x = 20; }
public class Test { public static void main(String[] args) { A a = new B(); System.out.println(a.x); } }
Q.50Hard
In Java, can you create an object of an abstract class?
Q.51Medium
Consider the code:
abstract class Animal { abstract void sound(); void sleep() { System.out.println("Zzz"); } }
class Dog extends Animal { void sound() { System.out.println("Bark"); } }
What can Dog objects do?
Q.52Hard
What is the main difference between method overriding and method overloading?
Q.53Easy
Which of the following correctly describes encapsulation?
Q.54Medium
Which statement is true about the default access modifier (package-private) in Java?
Q.55Easy
What happens when you try to instantiate an interface in Java?
Q.56Easy
Which keyword is used to achieve runtime polymorphism in Java?
Q.57Medium
What is the output of the following code?
class Parent { void show() { System.out.println("Parent"); } }
class Child extends Parent { void show() { System.out.println("Child"); } }
public class Test { public static void main(String[] args) { Parent p = new Child(); p.show(); } }
Q.58Easy
Can a class extend multiple classes in Java?
Q.59Medium
Which of the following statements about the 'final' keyword is correct?
Q.60Medium
What is the difference between 'this' and 'super' keywords?