Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Ready to master the art of inheritance in Java? Embark on this interactive quiz to test your knowledge and solidify your understanding of this fundamental object-oriented programming (OOP) concept.
Engage with 15 carefully crafted questions that delve into various aspects of inheritance, from class hierarchies and method overriding to access modifiers and real-world examples.
Whether you’re a Java beginner or an experienced developer, this quiz offers an engaging way to assess your skills and identify areas for further exploration. Let’s test your knowledge.
Time limit: 0
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Which of the following is the syntax of Simple inheritance in Java ?
Correct
Incorrect
Question 6 of 15
6. Question
class First {
private int x;
int y;
void method1( int z ) {
z = y + 5 ;
}
};
class Second extends First {
void method2 ( ) {
method1(5);
System.out.println(x);
}
};
class MainFunction {
public static void main ( String args [ ] )
{
Second obj = new Second();
obj.method2();
}
}
Correct
Incorrect
Question 7 of 15
7. Question
class One {
void display1 ( String a ) {
System.out.println(a);
}
};
class two {
void set1( String a , String b ) {
display1(String a) ;
}
void display2 ( String a, String b ) {
System.out.println(b);
}
};
class Third extends Second {
void set2( String a , String b , String c ) {
display2(String a , String b);
}
void display3(String a , String b , String c) {
System.out.println(c);
};
class Main {
public static void main ( String args [ ] )
{
Third obj = new Third();
obj.set2(“DataFlair” , “Webservices”);
obj.display3(“Pvt.Ltd”);
}
}
Correct
Incorrect
Question 8 of 15
8. Question
class Value {
void getNum ( ) {
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the radius of the Circle”);
float r = sc,nextInt();
}
int setValue ( ) {
return r;
}
};
class Diameter extends Value {
void CalculateDiameter (int r ) {
r = setValue();
double diameter = 2*r;
System.out,println(“The diameter of the circle is “ + diameter );
}
};
class Area extends Value {
void CalculateArea ( int a ) {
a = setValue();
double area = 3.14*r*r;
System.out.println(“Area of the Circle is “ + area );
}
};
class MainFunction {
public static void main ( String args [ ] )
{
Diameter object1 = new Diameter();
Area object2 = new Area():
object1.CalculateDiameter();
object2.CalculateArea();
}
}
Correct
Incorrect
Question 9 of 15
9. Question
If three classes namely B,C and D are inherited from a Class A, then the object should be created for which classes ?
Correct
Incorrect
Question 10 of 15
10. Question
class One {
void methodA ( ) {
System.out.println(“Method of class A is executed “);
}
};
class Two extends One {
void methodB ( ) {
System.out.println(“Method of class B is executed “);
}
};
class Three extends One {
void methodC ( ) {
System.out.println(“Method of class C is executed “);
}
};
class MainFunction {
public static void main ( String args [ ] )
{
One object = new One();
object.methodA();
object.methodB();
object.methodC();
}
}
Correct
Incorrect
Question 11 of 15
11. Question
interface Name {
void printValue(String text);
}
class InterfaceSample implements Name {
Public void printValue (String text ) {
System.out.println(text);
}
};
class MainFunction {
public static void main ( String args [ ] )
{
InterfaceSample i = new InterfaceSample();
obj.printValue(“DataFlair”);
}
}
Correct
Incorrect
Question 12 of 15
12. Question
Which of the following is not true about Interfaces in Java ?
Correct
Incorrect
Question 13 of 15
13. Question
class Members {
int a = 5;
double b = 5.5;
private int printMethod() {
System.out.println(“Method”);
return null;
};
class MainFunction extends Members {
public static void main ( String args [ ] )
{
Members o = new Members();
o.a = 10;
o.b = 5.7;
o.printMethod();
}
}
Correct
Incorrect
Question 14 of 15
14. Question
Which of the following is true about inheritance in Java ?
Correct
Incorrect
Question 15 of 15
15. Question
Which of the following is not a correct syntax for interfaces in Java ?
Correct
Incorrect
Summary:
Congratulations on completing the quiz on inheritance in Java! By tackling these thought-provoking questions, you’ve deepened your understanding of this crucial OOP concept and put your knowledge to the test. Remember, inheritance is a powerful tool for code reuse, organization, and extensibility in Java.
Continue your learning journey by exploring additional resources, practising with more complex examples, and applying inheritance to real-world projects. Embrace the challenge, and you’ll unlock the full potential of inheritance to create flexible and maintainable Java applications.
You give me 15 seconds I promise you best tutorials Please share your happy experience on Google
DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.