0
0
Javaprogramming~10 mins

Partial abstraction in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an abstract class named Vehicle.

Java
public [1] class Vehicle {
    // class body
}
Drag options to blanks, or click blank then click option'
Aprivate
Bfinal
Cstatic
Dabstract
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'final' instead of 'abstract' will prevent the class from being subclassed.
Using 'static' or 'private' keywords here is incorrect for class declaration.
2fill in blank
medium

Complete the code to declare an abstract method named startEngine in the Vehicle class.

Java
public abstract class Vehicle {
    public [1] void startEngine();
}
Drag options to blanks, or click blank then click option'
Aabstract
Bstatic
Cfinal
Dprivate
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'final' or 'static' keywords with abstract methods is not allowed.
Forgetting the semicolon at the end of the method declaration.
3fill in blank
hard

Fix the error in the subclass Car that extends Vehicle by correctly overriding the abstract method startEngine.

Java
public class Car extends Vehicle {
    @Override
    public void [1] {
        System.out.println("Engine started");
    }
}
Drag options to blanks, or click blank then click option'
AstartEngine()
BstartEngine(void)
CstartEngine
DstartEngine[]
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Omitting parentheses after the method name causes a syntax error.
Using incorrect parameter syntax like 'void' inside parentheses.
4fill in blank
hard

Fill both blanks to declare an abstract class Shape with an abstract method draw.

Java
public [1] class Shape {
    public [2] void draw();
}
Drag options to blanks, or click blank then click option'
Aabstract
Bfinal
Dstatic
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'final' or 'static' keywords instead of 'abstract' for class or method.
Providing a method body for an abstract method.
5fill in blank
hard

Fill all three blanks to create a subclass Circle that extends Shape and implements the draw method.

Java
public class Circle extends [1] {
    @Override
    public void [2] {
        System.out.println([3]);
    }
}
Drag options to blanks, or click blank then click option'
AShape
Bdraw()
C"Drawing a circle"
DShape()
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using constructor syntax 'Shape()' instead of class name in extends.
Omitting parentheses in method override.
Forgetting to put the message inside quotes.