Vidyalelo
Java Programming · all questions

Inheritence
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

86

Questions

1/5

Page

Pick an option on a question to see the right answer and solution.

What is inheritance in Java?

Select an option to see the answer and solution.

In Java, which keyword is used to implement inheritance between classes?

Select an option to see the answer and solution.

What is a superclass in Java?

Select an option to see the answer and solution.

In Java, can a subclass inherit constructors from its superclass?

Select an option to see the answer and solution.

What is method overriding in Java?

Select an option to see the answer and solution.

In Java, can a subclass override a private method from its superclass?

Select an option to see the answer and solution.

What is the "super" keyword used for in Java?

Select an option to see the answer and solution.

What is the result of the following code snippet?

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

Select an option to see the answer and solution.

In Java, can a subclass access private members (fields and methods) of its superclass?

Select an option to see the answer and solution.

What is the difference between "extends" and "implements" in Java?

Select an option to see the answer and solution.

In Java, can a subclass access protected members (fields and methods) of its superclass?

Select an option to see the answer and solution.

What is the result of the following code snippet?

class Parent {
protected void display() {
System.out.println("Parent");
}
}
class Child extends Parent {
void show() {
display();
}
}
public class Main {
public static void main(String[] args) {
Child obj = new Child();
obj.show();
}
}

Select an option to see the answer and solution.

In Java, can a subclass have more than one superclass?

Select an option to see the answer and solution.

What is the purpose of the "final" keyword in Java inheritance?

Select an option to see the answer and solution.

In Java, can a subclass inherit private constructors from its superclass?

Select an option to see the answer and solution.

What is the concept of method overriding in Java inheritance?

Select an option to see the answer and solution.

In Java, can a subclass inherit static methods from its superclass?

Select an option to see the answer and solution.

What is the result of the following code snippet?

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

Select an option to see the answer and solution.

In Java, can a subclass access package-private members (fields and methods) of its superclass defined in another package?

Select an option to see the answer and solution.

What is the result of the following code snippet?

class Parent {
int x = 10;
}
class Child extends Parent {
int x = 20;
void display() {
System.out.println(super.x + " " + x);
}
}
public class Main {
public static void main(String[] args) {
Child obj = new Child();
obj.display();
}
}

Select an option to see the answer and solution.