Which of the following statements about 'instanceof' operator is true?
Answer: B
The 'instanceof' operator is used to test if an object is an instance of a specified class, subclass, or interface. It returns a boolean value.
Q.62Medium
In the context of constructors, which statement is correct?
Answer: B
Constructor overloading is allowed in Java. A class can have multiple constructors with different parameter lists. Constructors don't have return types and can have any access modifier.
Q.63Medium
What is the difference between 'this' and 'super' keywords in Java?
Answer: B
'this' is a reference to the current object instance, while 'super' is a reference to the parent class object. They are used to access members of current and parent classes respectively.
Q.64Medium
Which of the following best describes polymorphism in Java?
Answer: B
Polymorphism allows objects to be treated as instances of their parent class and to call methods that are overridden in child classes. It includes method overloading and method overriding.
Q.65Medium
An abstract class in Java cannot be instantiated, but it can have concrete methods. Which statement explains why?
Answer: B
Abstract classes cannot be instantiated but can contain both abstract methods (without implementation) and concrete methods (with implementation). This allows providing default behavior while enforcing certain methods to be implemented by subclasses.
Advertisement
Q.66Medium
Which of the following correctly implements method overloading rules in Java?
Answer: B
Method overloading requires methods to have the same name but different parameter lists (different types, number, or order of parameters). Return type alone cannot distinguish overloaded methods.
Q.67Medium
Which statement about interface implementation in Java is true?
Answer: D
Java 8 introduced default and static methods in interfaces. Any class implementing an interface must provide implementations for all its abstract methods (unless the implementing class is abstract).
Q.68Medium
Which statement about the 'protected' access modifier is correct?
Answer: B
'protected' members are accessible within the same package and also to subclasses in different packages. It provides more access than default but less than public.
Q.69Medium
Which of the following is NOT a characteristic of an interface in Java?
Answer: C
Interfaces cannot have instance variables (private or otherwise). They can only have constants (static final). Java 9+ allows private methods but not private instance variables.
Q.70Medium
What will happen if you try to override a final method in a child class?
Answer: B
Final methods cannot be overridden. The compiler will throw an error indicating that you cannot override a final method.
Q.71Medium
Which statement about 'this' keyword is correct?
Answer: B
'this' is a reference variable that refers to the current object instance. It is commonly used to distinguish instance variables from parameters with the same name.
Q.72Medium
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?
Answer: B
When a class implements multiple interfaces with the same method signature, a single method implementation satisfies all interfaces. This is resolved at compile time.
Q.73Medium
What is method overloading?
Answer: A
Method overloading allows multiple methods with the same name but different parameters (number, type, or order). It is a compile-time (static) polymorphism.
Q.74Medium
Which of the following is true about abstract classes?
Answer: A
Abstract classes can have constructors to initialize instance variables. They can contain both abstract and concrete methods, and they cannot be directly instantiated.
Q.75Medium
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?
Answer: C
Dog inherits the concrete method sleep() from Animal and provides implementation for the abstract method sound(). Therefore, Dog objects can call both methods.
Q.76Medium
Which statement is true about the default access modifier (package-private) in Java?
Answer: B
The default (package-private) access modifier allows access to members from any class within the same package, but not from classes in other packages.
Q.77Medium
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(); } }
Answer: B
This demonstrates runtime polymorphism. Although the reference is of type Parent, the actual object is Child. The overridden show() method in Child class is executed.
Q.78Medium
Which of the following statements about the 'final' keyword is correct?
Answer: C
The 'final' keyword when applied to a variable makes it a constant. When applied to a class, it cannot be extended. When applied to a method, it cannot be overridden.
Q.79Medium
What is the difference between 'this' and 'super' keywords?
Answer: B
'this' is a reference to the current object instance, while 'super' is a reference to the parent class. They serve different purposes in inheritance hierarchy.
Q.80Medium
Consider a scenario where class B extends class A. If class A has a constructor with parameters, what must class B do?
Answer: B
If a parent class has a parameterized constructor and no default constructor, the child class must explicitly call it using super() to initialize parent class members.