Site icon DataFlair

Quiz on Inheritance in Java

quiz on inheritance in java

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.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    class Inheritance {

    void display( ) {

    System.out.println(“DataFlair”);

    }

    };

    class Subclass extends Inheritance {

    void show() {

    System.out.println(“web services”);

    }

    };

    class MainFunction {

    public static void main ( String args [ ] )

    {

    Subclass obj = new Subclass();

    obj.display();

    obj.show();

    }

    }

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    class First {

    int method(int a) {

    return a*a;

    }

    };

    class Second extends First{

        void method1() {

        System.out.println(a+a);

        }

    };

    class MainFunction {

    public static void main ( String args [ ] );

    First obj = new First ();

    System.out.println(obj.method(3));

    obj.method1(3);

    }

    }

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    class Constructors {

    private method ( int x  ) {

    return x;

    }

    };

    class Second extends Constructors {

    Void display (int x ) { 

     System.out.println(x*x);

    }

    };

    class MainFunction {

    public static void main ( String args [ ] ) 

    {

    Second obj – new Second();

    obj.method(3 );

    obj.display( 3) ;

    }

    }

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    class A {

    void classAMethods ( ) {

    }

    };

    class B extends A {

    void classBMethods() {

    }

    };

    class C extends B {

    void classCMethods ( ) {

    }

    };

    class MainFunction {

    public static void main ( String args [ ] )

    {

    C object = new C;

    object.classAMethods( );

    object.classBMethods( );

    object.classCMethods( );

    }

    }

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    Which of the following is the syntax of Simple inheritance in Java ?

    Correct
    Incorrect
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. Question 12 of 15
    12. Question

    Which of the following is not true about Interfaces in Java ?

    Correct
    Incorrect
  13. 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
  14. Question 14 of 15
    14. Question

    Which of the following is true about inheritance in Java ?

    Correct
    Incorrect
  15. 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.

Exit mobile version