Java Methods and Constructors Quiz

  • Post category:Java Quiz
  • Reading time:1 mins read

Java Methods and Constructors Quiz

You’ve learned a lot, and now it’s time to test yourself with this Methods and Constructors Quiz. This is a great way to check your knowledge and skills. This quiz will help you see how much you’ve learned and identify areas you might need to review.

If you’re new, don’t worry—this will be very helpful for you. We’ve already covered many Java quizzes, so if you haven’t checked your skills with those, be sure to test yourself in the other Java quiz categories too.

1 / 15

1. Which of the following is true about constructor overloading?

2 / 15

2. Which of the following statements is true about static blocks?

3 / 15

3. Which of the following is true about static methods?

4 / 15

4. What will be the output of the following code?

class A {

    A() {

        System.out.println(“A”);

    }

}

class B extends A {

    B() {

        System.out.println(“B”);

    }

}

class C extends B {

    C() {

        System.out.println(“C”);

    }

}

public class Main {

    public static void main(String[] args) {

        C c = new C();

    }

}

5 / 15

5. What will be the output of the following code?

class Parent {

    Parent() {

        System.out.println(“Parent Constructor”);

    }

}

class Child extends Parent {

    Child() {

        System.out.println(“Child Constructor”);

    }

}

public class Main {

    public static void main(String[] args) {

        Child c = new Child();

    }

}

6 / 15

6. Which of the following is true about the `super` keyword in Java?

7 / 15

7. What is a default constructor?

8 / 15

8. What will be the output of the following code?

 

   class A {

       void display(int a) {

           System.out.println(“Class A”);

       }

   }

   class B extends A {

       void display(double a) {

           System.out.println(“Class B”);

       }

   }

   public class Main {

       public static void main(String[] args) {

           B obj = new B();

           obj.display(5);

       }

   }

9 / 15

9. Which of the following is true about method overloading?

10 / 15

10. What will be the output of the following code?

 

   class Demo {

       int x;

       Demo() {

           this(10);

           System.out.println(“Default constructor”);

       }

       Demo(int x) {

           this.x = x;

           System.out.println(“Parameterized constructor”);

       }

   }

   public class Main {

       public static void main(String[] args) {

           Demo obj = new Demo();

       }

   }

11 / 15

11. Which keyword is used to call a constructor from another constructor in the same class?

12 / 15

12. Can a Java class have multiple constructors?

13 / 15

13.  

What will be the output of the following code?

 

   class Test {

       int x;

       Test(int x) {

           this.x = x;

       }

       void display() {

           System.out.println(x);

       }

   }

   public class Main {

       public static void main(String[] args) {

           Test obj = new Test(5);

           obj.display();

       }

   }

14 / 15

14. Which of the following is true about constructors?

15 / 15

15. What is the difference between a constructor and a method in Java?

Your score is