The following code contains a compilation error , what can be done to fix this error – independently?

abstract class AirPlane 
{ // line 1  
    abstract void fly(); // line 2  
    void land()
    {
        System.out.print("Landing..");
    }
}
class AirJet extends AirPlane 
{ // line 10  
    AirJet()
    {
        super(); // line 13  
    }
    void fly() 
    {
        System.out.print("Flying..");
    }
    abstract void land(); // line 20 
}

Please choose all the answers that apply:
a) Remove abstract from line 20 and add body to method land()

b) Declare class AirJet as abstract to at line 10

c) Remove super() call at line 13

d) Remove abstract at line 1 and line 2

  1. a, b

  2. a, c

  3. b, c

  4. c, d


Correct Option: A
Explanation:

To fix the compilation error in the given code, we need to understand the concept of abstract classes and methods in Java.

An abstract class is a class that cannot be instantiated, and it can have abstract methods, which are declared without an implementation. Any subclass of an abstract class must either implement all the abstract methods of its parent class or be declared as abstract itself.

In the given code, we have an abstract class AirPlane and its subclass AirJet. AirPlane has one abstract method fly() and one non-abstract method land(), while AirJet overrides the fly() method and declares another abstract method land().

The compilation error in the code is due to the fact that AirJet is not implementing all the abstract methods of its parent class AirPlane. To fix this error, we have two options:

a) Remove abstract from line 20 and add body to method land()

This option is correct. Since AirJet is a concrete class, it must implement all the abstract methods of its parent class AirPlane. Therefore, we can remove the abstract keyword from the declaration of land() method and provide an implementation for it.

b) Declare class AirJet as abstract to at line 10

This option is incorrect. Declaring AirJet as abstract will not solve the compilation error. In fact, it will introduce another error because AirJet will now have two abstract methods, but it is not declaring itself as abstract.

c) Remove super() call at line 13

This option is incorrect. Removing the super() call will not solve the compilation error. In fact, it will introduce another error because AirPlane does not have a default constructor, and super() is trying to call it.

d) Remove abstract at line 1 and line 2

This option is incorrect. Removing the abstract keyword from line 1 and line 2 will not solve the compilation error. In fact, it will introduce another error because now AirPlane will have a non-implemented method.

Therefore, the correct answer is:

The Answer is: A. a, b

Find more quizzes: