1
2
3
100

What keyword is used to create a subclass in Java?

extends

100

What keyword is used to access a superclass's members from a subclass?

super

100

True or False: A class can inherit from multiple classes in Java.

False

200

When a subclass has a method with the same signature as a method in the parent class, it is said to _________ the parent method.

a. extend

b. override

c. overload

d. polymorph

override

200

What type of polymorphism is achieved by having multiple methods with the same name but different parameters?

a. method overriding

b. method overloading

c. class deriving

d. polytypism

method overloading

200

What type of polymorphism is achieved by a subclass providing a specific implementation of a method declared in its superclass?

a. method overriding

b. method overloading

c. class deriving

d. polytypism

method overriding

300

What is the process by which Java can determine which method to invoke when methods have been overridden?

a. compile-time polymorphism

b. overloading polymorphism

c. overriding polymorphism

d. runtime polymorphism

runtime polymorphism

300

Which keyword is used to add an interface class into another class?

What is implements?

300

When you call the super() in the constructor of the subclass, where does it have to be?

in the first line of the body of the constructor

400

Which of the following is true about inheritance in Java?
1) Private methods are final.
2) Protected members are accessible within a package and inherited classes outside the package.
3) Protected methods are final.
4) We cannot override private methods.

1, 2 and 4

400

class Base {public void Print() {

 System.out.println("Base");} }

class Derived extends Base {   public void Print() {

 System.out.println("Derived");}}

class Main{public static void DoPrint( Base o ) {

 o.Print();}

    public static void main(String[] args) {

        Base x = new Base();

        Base y = new Derived();

        Derived z = new Derived();

        DoPrint(x);  DoPrint(y);  DoPrint(z);}}

Base

Derived

Derived

400

What is the ability to call a method on a parent class in a child class? 

ex. speak() in a Pet class, without knowing whether the Pet object is really a Cat, Dog, AngryBird, etc.

polymorphism

500

class Base {

    public void foo() { System.out.println("Base"); }}

class Derived extends Base {

    private void foo() { System.out.println("Derived");}}

public class Main {

    public static void main(String args[]) {

        Base b = new Derived();

        b.foo();   }} 

Compiler Error

500

class Animal { public void makeSound() {

        System.out.println("Animal sound"); }}

class Dog extends Animal {

    @Override

    public void makeSound() {System.out.println("Woof!");  }}

public class Test {

    public static void main(String[] args) {

        Animal animal = new Animal();

        Animal dog = new Dog();

        animal.makeSound();

        dog.makeSound();  }}

Animal sound

Woof!

500

Which Java modifiers such as public, final, and static can be used in interface and abstract classes?

What is "Interface can only use the public modifier while abstract can use any"