🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Welcome to Java Inheritance Quiz!. This Java Inheritance Quiz consists of important 20 multiple-choice questions (MCQ) with answers and explanations. Go ahead and test your knowledge of the Java Inheritance concept.
The first 10 questions are very simple and the remaining 10 questions are medium and complex.
1. What is Inheritance in Java programming?
Answer:
Explanation:
2. Which keyword is used for inheritance in Java?
Answer:
Explanation:
3. Can a class inherit constructors from its superclass in Java?
Answer:
Explanation:
4. What is a subclass in Java inheritance?
Answer:
Explanation:
5. What is the parent class of all classes in Java?
Answer:
Explanation:
6. Can we perform multiple inheritance in Java?
Answer:
Explanation:
7. What is the purpose of the 'super' keyword in Java?
Answer:
Explanation:
8. Can a subclass inherit private members of its superclass?
Answer:
Explanation:
9. What is a multilevel inheritance in Java?
Answer:
Explanation:
10. Can interfaces be used to achieve multiple inheritance in Java?
Answer:
Explanation:
11. In Java, is it possible to override a static method?
Answer:
Explanation:
12. What is the output of the following Java program?
public class Vehicle {
public void move() {
System.out.println("The vehicle moves");
}
}
public class Car extends Vehicle {
public void move() {
System.out.println("The car moves");
}
}
public class Main {
public static void main(String[] args) {
Vehicle vehicle = new Car();
vehicle.move();
}
}
Answer:
Explanation:
13. What is the output of the following Java program?
class Parent {
String name = "parent";
String message() {
return "from parent";
}
}
class Child extends Parent {
String name = "child";
String message() {
return "from child";
}
}
public class Main {
public static void main(String[] args) {
Parent p = new Child();
System.out.println(p.name + " " + p.message());
}
}
Answer:
Explanation:
14. What is the output of the following Java program?
class Grandparent {
public void print() {
System.out.println("Grandparent's Print()");
}
}
class Parent extends Grandparent { }
class Child extends Parent { }
public class Main {
public static void main(String[] args) {
Child child = new Child();
child.print();
}
}
Answer:
Explanation:
15. What will be the output of the following program?
class First
{
static void staticMethod()
{
System.out.println("Static Method");
}
}
public class MainClass
{
public static void main(String[] args)
{
First first = null;
first.staticMethod();
}
}
Answer:
Explanation:
16. What is the output of the following Java program?
class One{
public One(){
System.out.print("One,");
}
}
class Two extends One{
public Two(){
System.out.print("Two,");
}
}
class Three extends Two{
public Three(){
System.out.print("Three");
}
}
public class Test{
public static void main(String[] args){
Three three = new Three();
}
}
Answer:
Explanation:
17. What is the output of the following Java program?
class FirstClass
{
public FirstClass()
{
System.out.println("Constructor of FirstClass");
}
}
class SecondClass extends FirstClass
{
public SecondClass()
{
System.out.println("Constructor of SecondClass");
}
}
class ThirdClass extends SecondClass
{
public ThirdClass()
{
System.out.println("Constructor of ThirdClass");
}
}
public class Main
{
public static void main(String[] args)
{
ThirdClass instanceOfThirdClass = new ThirdClass();
}
}
Answer:
Explanation:
18. What is the output of the following Java program?
class ParentClass
{
static void displayMessage()
{
System.out.println("ParentClass Display");
}
}
class ChildClass extends ParentClass
{
static void displayMessage()
{
System.out.println("ChildClass Display");
}
}
public class Main
{
public static void main(String[] args)
{
ChildClass.displayMessage();
}
}
Answer:
Explanation:
19. What is the output of the following Java program?
class ClassAlpha
{
{
System.out.println("Alpha");
}
}
class ClassBeta extends ClassAlpha
{
{
System.out.println("Beta");
}
}
class ClassGamma extends ClassBeta
{
{
System.out.println("Gamma");
}
}
public class Main
{
public static void main(String[] args)
{
ClassGamma gamma = new ClassGamma();
}
}
What will be the output when this program is run?
Answer:
Explanation:
20. What is the output of the following Java program?
class ClassOne
{
int variableOne = 10;
}
class ClassTwo extends ClassOne
{
int variableOne = 20;
}
public class Main
{
public static void main(String[] args)
{
ClassOne objOne = new ClassTwo();
System.out.println(objOne.variableOne);
}
}
Answer:
Explanation:
Conclusion
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment