menu

Inheritance in Java

Inheritance in Java - Important Points


31. Which keyword is used to implement method overriding in Java?

A. override

B. final

C. abstract

D. none of the above

Discuss Work Space

Answer: option a

Explanation:

The 'override' keyword is used to implement method overriding in Java.

32. Which of the following is not a superclass of the String class in Java?

A. Object

B. CharSequence

C. Number

D. Comparable

Discuss Work Space

Answer: option c

Explanation:

Number is not a superclass of the String class in Java.

33. What is the purpose of the 'super' keyword in Java?

A. To call a method or constructor of a superclass

B. To declare a superclass

C. To access a private field of a superclass

D. To override a method of a superclass

Discuss Work Space

Answer: option a

Explanation:

The 'super' keyword is used to call a method or constructor of a superclass in Java.

34. Which of the following statements is true regarding the 'this' keyword in Java?

A. It can be used to access a static field of a class.

B. It can be used to call a method of a superclass.

C. It can be used to refer to the current instance of a class.

D. It can be used to declare a constructor.

Discuss Work Space

Answer: option c

Explanation:

The 'this' keyword is used to refer to the current instance of a class in Java.

35.

What is the output of the following program?

class A {
void display() {
System.out.println("Class A");
}
}
class B extends A {
void display() {
super.display();
System.out.println("Class B");
}
}
public class Main {
public static void main(String[] args) {
B obj = new B();
obj.display();
}
}

A. Class A, Class B

B. Class B, Class A

C. Class A

D. Class B

Discuss Work Space

Answer: option a

Explanation:

The output of the above code will be 'Class A, Class B', as the 'display()' method in class B calls the 'display()' method of class A using the 'super' keyword, followed by printing 'Class B'.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now