What is the output of the following code?
class A {
int x = 10;
}
class B extends A {
int x = 20;
}
public class Test {
public static void main(String[] args) {
A obj = new B();
System.out.println(obj.x);
}
}
Q.2Medium
Which of the following statements about abstract classes is TRUE?
Q.3Medium
What will happen when you try to instantiate an interface in Java?
Q.4Medium
Which of the following best describes encapsulation?
Q.5Medium
Which of the following is true about method overloading?
Advertisement
Q.6Medium
What is the correct way to prevent a class from being inherited in Java?
Q.7Medium
What is the output?
class A {
A() {
System.out.println("A");
}
}
class B extends A {
B() {
super();
System.out.println("B");
}
}
public class Test {
public static void main(String[] args) {
new B();
}
}
Q.8Medium
Which of the following statements about 'instanceof' operator is correct?
Q.9Medium
Which of the following statements about inheritance in Java is correct?
Q.10Medium
Which of the following correctly describes method overriding in Java?
Q.11Medium
Which of the following statements about 'instanceof' operator is true?
Q.12Medium
In the context of constructors, which statement is correct?
Q.13Medium
What is the difference between 'this' and 'super' keywords in Java?
Q.14Medium
Which of the following best describes polymorphism in Java?
Q.15Medium
An abstract class in Java cannot be instantiated, but it can have concrete methods. Which statement explains why?
Q.16Medium
Which of the following correctly implements method overloading rules in Java?
Q.17Medium
Which statement about interface implementation in Java is true?
Q.18Medium
Which statement about the 'protected' access modifier is correct?
Q.19Medium
Which of the following is NOT a characteristic of an interface in Java?
Q.20Medium
What will happen if you try to override a final method in a child class?