menu

Inheritance in Java

Inheritance in Java - Important Points


21. Which keyword is used to implement method overloading in Java?

A. override

B. final

C. abstract

D. none of the above

Discuss Work Space

Answer: option d

Explanation:

The 'override' keyword is used to implement method overriding, not method overloading.

22. Which keyword is used to prevent a class from being inherited in Java?

A. final

B. static

C. abstract

D. private

Discuss Work Space

Answer: option a

Explanation:

The 'final' keyword is used to prevent a class from being inherited in Java.

23.

What is the output of the following program?

class A {
int x = 10;
}
class B extends A {
int y = 20;
}
class C extends B {
void display() {
System.out.println(x + y);
}
}
public class Main {
public static void main(String[] args) {
C obj = new C();
obj.display();
}
}

A. 30

B. 20

C. 10

D. Compilation error

Discuss Work Space

Answer: option a

Explanation:

The output of the above code will be 30 as the 'display()' method in class C adds the values of 'x' and 'y'.

24. Which of the following statements is true regarding inheritance in Java?

A. A class can inherit from multiple classes in Java.

B. A subclass can access private members of its superclass.

C. Constructors are not inherited in Java.

D. Inheritance is not supported in Java.

Discuss Work Space

Answer: option c

Explanation:

Constructors are not inherited in Java.

25. Which keyword is used to implement an abstract method in a subclass in Java?

A. abstract

B. final

C. static

D. override

Discuss Work Space

Answer: option d

Explanation:

The 'override' keyword is used to implement an abstract method in a subclass in Java.


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