Inheritance

6.What will happen if a class extends two classes in Java?
  • A. Compilation error
  • B. The last extended class is considered
  • C. Only one superclass is inherited
  • D. Java will allow it using implements

Compilation error

Compilation error

7.What will happen if a subclass does not provide a constructor and the superclass only has a parameterized constructor?
  • A. The program compiles and runs normally
  • B. Compilation error due to the missing default constructor in the superclass
  • C. The superclass constructor is automatically called with default values
  • D. The subclass inherits the parameterized constructor

Compilation error due to the missing default constructor in the superclass

Compilation error due to the missing default constructor in the superclass

8.What happens when a subclass constructor explicitly calls super(arguments)?
  • A. It must be the first statement in the constructor
  • B. It can be placed anywhere in the constructor
  • C. It overrides the superclass constructor
  • D. It prevents the superclass constructor from executing

It must be the first statement in the constructor

It must be the first statement in the constructor

9.What happens when a subclass constructor explicitly calls super(arguments)?
  • A. It must be the first statement in the constructor
  • B. It can be placed anywhere in the constructor
  • C. It overrides the superclass constructor
  • D. It prevents the superclass constructor from executing

It must be the first statement in the constructor

It must be the first statement in the constructor

10.How can we call the parent class’s private method in a subclass?
  • A. Using super.methodName();
  • B. Using this.methodName();
  • C. By making the method protected or public in the superclass
  • D. Private methods cannot be accessed in subclasses

Private methods cannot be accessed in subclasses

Private methods cannot be accessed in subclasses