Site icon DataFlair

Quiz on Abstract Class in Java

quiz on abstract class in java

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

Abstract classes are a cornerstone of object-oriented programming (OOP) in Java. They act as a template, defining a blueprint for creating families of related objects. This approach not only promotes code reusability but also enforces a common structure and behavior across these objects. Imagine a blueprint for a house – it defines the overall layout, foundation, and basic elements that all houses share.

Abstract classes work in a similar way, providing a foundation for related objects while allowing flexibility for specific implementations. Just like different house plans might specify unique features like the number of bedrooms or presence of a garage, subclasses of an abstract class can provide their own concrete implementations for specific functionalities.

This quiz on abstract classes in Java delves into these key characteristics and functionalities, helping you solidify your understanding of this powerful concept. By tackling the challenges presented, you’ll gain valuable insights into how abstract classes promote code organization, reusability, and flexibility in object-oriented programming.

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 is true about abstract classes in Java ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    abstract class AbstractClass {

    public void method();

    }

    class Subclass derived AbstractClass {

    public void method(String a) 

    {

    System.out.println(a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    AbstractClass a = new Subclass();

    a.method(“DataFlair”);

    }

    }

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    abstract class One {

    One() {

    System.out.println(“Constructor is called”);

    }

    abstract void function();

    }

    class Demo extends One {

    abstract void abstract()

    {

    System.out.println(“Subclass constructor is called”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    One o = new One();

    }

    }

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following is not true about abstract classes in Java ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    class Demo {

    abstract void method1();

    }

    class Sample extends Demo {

    abstract void method1() {

    System.out.println(“This is a Sample Class”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Demo d = new Sample();

    d.method1();

    }

    }

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    abstract class Abstraction {

    abstract void calculate(int a , int b) 

    {

    System.out.println(a*b);

    }

    ]

    class Sample extends Abstraction {

    public void calculate( int a , int b );

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Abstraction a = new Sample();

    a.calculate(2,4);

    }

    }

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which keyword is used to inherit an abstract class ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

     abstract class Abstraction {

    public void Square(int a);

    }

    class Example extends Abstraction {

    public Example() {

    System.out.println(“Constructor”);

    }

    public void Square(int a )

    {

    System.out.println(a*a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Abstraction a = new Example();

    a.Square(3);

    }

    }

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

    abstract class First {

    First() {

    System.out.println(“ Abstract class constructor”);

    }

    public void math(int a , int b );

    }

    class Function extends First {

    Function() {

    System.out.println(“Extended class constructor”);

    }

    public void math( int a , int b )

    {

    System.out.println(a+b);

    }

    }
    class Main {

    public static void main ( String args [ ] )

    {

    First f = new Function();

    f.math(3,8);

    }

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of these is not used to declare a method in abstract class ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    abstract class SampleClass {

    public void demo ( ) 

    {

    System.out.println(“Method is defined here”);

    }

    class Second extends SampleClass {

    }

    class Main {

    public static void main ( String args [ ] )

    {

    SampleClass s = new Second();

    s.demo();

    }

    }

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

    abstract class AbstractionDemo {

    abstract void display();

    }

    class Main extends Abstraction demo {

    public static void main ( String args [ ] )

    {

    abstract void display()

    {

    System.out.println(“Main Function”);

    }

    AbstractionDemo d = new Main();

    d.display();

    }

    }

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

     What is the reason for constructor in abstract class ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

    abstract class Super {

    public void simple(String a);

    }

    class Sub extends Super {

    public void simple(String a)

    {

    System.out.println(a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Super s = new Super();

    s.simple(“DataFlair”);

    }

    }

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    abstract class Main {

    static void function() {

    System.out.println(“Static method”);

    }

    class MainFunction extends Main {

    public static void main ( String args [ ] )

    {

    Main.function();

    }

    }

    Correct
    Incorrect

Summary:

So you’ve taken the quiz and put your knowledge of abstract classes in Java to the test! How did you fare? Regardless of your score, this quiz serves as a valuable learning tool. For any questions answered incorrectly, revisit the explanations provided to solidify your understanding.

Remember, effective mastery of abstract classes is crucial for building robust and maintainable object-oriented applications in Java. Explore additional resources beyond this quiz, such as tutorials and practice problems, to further enhance your grasp of this important concept.

Exit mobile version