Site icon DataFlair

Quiz on Java Method Overriding

quiz on java method overriding

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Method overriding is a cornerstone of object-oriented programming in Java. It allows subclasses to inherit methods from their parent classes and provide specialized implementations. This powerful mechanism promotes code reusability and flexibility while fostering a clear hierarchy within your application’s architecture.

This quiz will test your understanding of key concepts related to method overriding in Java. By answering the questions, you’ll solidify your grasp of when and how to effectively override methods in your Java projects.

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

    Which of the following defines method overriding?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    class Sample {

    void print() {

    System.out.println(“Superclass Method”);

    }

    };

    class Example extends Sample {

    void print() {

    System.out.println(“Subclass Method”);

    }

    };

    class Main {

    public static void main ( String args [ ] )

    {

    Sample s = new Example () ;

    s.print();

    s.print();

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    Class Methods {

    void method1 ( int a) {

    System.out.println(a*a);

    }

    };

    class Sample extends Methods {

    void method1 ( int a ) {

    System.out.println(a+a);

    }

    };

    class Main {

    public static void main ( String args [ ] ) 

    {

    Methods m = new Methods();

    Methods obj = new Sample();

    m.method1(3);

    obj.method1(5);

    }

    }

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following is exhibited by Method overriding ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    class Override {

    void display() {

    System.out.println(“DataFlair”);

    }

    };

    class Method extends Override {

    void display(String a) { 

    System.out.println(a);

    }

    };

    class Main {

    public static void main ( String args [ ] )

    {

    Override o = new Override();

    o.display();

    Override o = new Method();

    o.display(“DataFlair”);

    }

    }

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    class MethodOverride {

    static void m1 ( ) {

    System.out.println(“ This is a superclass static method “);

    }

    }

    class Override extends MethodOverride{

    static void m1 ( ) {

    System.out.println(“ This is a subclass static method “); 

    }

    };

    class Main {

    public static void main ( String args [ ] )

    {

    MethodOverride r = new Override();

    r.m1();

    }

    }

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which of the following is not present in method overriding ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

     class Demo {

    final void calculate ( int a , int b ) 

    {

    int area = a*b;

    System.out.println(area);

    }

    };

    class Perimeter extends Demo {

    void calculate ( int a , int b )

    {

    int perimeter = a+a+b+b;

    System.out.println(perimeter);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Demo d = new Demo();

    d.calculate(1,2);

    Demo d = new Perimeter();

    d.calculate(1,2);

    }

    }

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

    class Area {

    public Area ( int a ) {

    a +=5;

    }

    };

    class Sample extends Area {

    public Sample ( int a) {

    a = a+5;

    }

    void calculate {

    System.out.println(a*a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Area a = new Area();

    a.Sample(5);

    Sample s = new Sample();

    s.calculate(a);

    }

    }

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of the following cannot be overridden by Method Overriding ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class Example {

    void method ( String a) {

    System.out.println(a);

    }

    void method( String b) {

    System.out.println(b);

    }

    public static void main ( String args [ ] )

    {

    Example e = new Example ();

    e.method(“DataFlair”);

    }

    }

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

     interface One {

    void print();

    }

    class Two implements One {

    void print() {

    System.out.println(“Interface is implemented”);

    }

    }

    class Three extends Two {

    void print() {

    System.out.println(“Interface is implemented and class is also extended”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    One o = new Three();

    o.print();

    }

    }

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

     Which of the given words are not used in method overridden concepts ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

     class MethodOverridingDemo {

    string a = “Superclass”;

    void display () {

    System.out.println(a);

    }

    }

    class Demo extends MethodOverridingDemo {

    String a = “Subclass”;

    void display() {

    System.out.println(a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    MethodOverridingDemo d = new Demo();

    d.display();

    }

    }

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    final class First {

    int a = 10;

    void display() {

    System.out.println(a);

    }

    }

    class Second extends First {

    int b = 15;

    void display() {

    System.out.println(b + a);

    }

    }

    class Third extends Second {

    int c = 20;

    void display() {

    System.out.println(c+b+a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    First f = new Third();

    f.display();

    }

    }

    Correct
    Incorrect

Summary:

So you’ve taken the quiz and challenged your knowledge of Java method overriding! Did you identify the correct answers with ease, or were there a few concepts that required revisiting? Regardless of your score, this quiz served as a valuable learning tool.

Remember, effective mastery of method overriding requires consistent practice. Explore additional resources beyond this quiz, such as tutorials, code examples, and discussions with fellow Java programmers. By actively engaging with various learning materials, you’ll solidify your understanding and become proficient in crafting well-structured and reusable Java code.

Exit mobile version