0
0
Javaprogramming~10 mins

OOP principles overview 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 a class named Car.

Java
public class [1] {
    // class body
}
Drag options to blanks, or click blank then click option'
ACar
Bcar
CVehicle
DcarClass
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase for class names
Using a different name than intended
2fill in blank
medium

Complete the code to create an object of class Car.

Java
Car myCar = new [1]();
Drag options to blanks, or click blank then click option'
AVehicle
Bcar
CCar
DMyCar
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase or different names
Using a class name that does not exist
3fill in blank
hard

Fix the error in the code to properly override the method start in class Car.

Java
public class Car {
    public void start() {
        System.out.println("Car started");
    }
}

public class SportsCar extends Car {
    @Override
    public void [1]() {
        System.out.println("SportsCar started fast");
    }
}
Drag options to blanks, or click blank then click option'
AStart
Brun
Cbegin
Dstart
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using uppercase first letter in method name
Using a different method name
4fill in blank
hard

Fill both blanks to define a class that inherits from Vehicle and overrides the move method.

Java
public class Car [1] Vehicle {
    @Override
    public void [2]() {
        System.out.println("Car is moving");
    }
}
Drag options to blanks, or click blank then click option'
Aextends
Bimplements
Cmove
Dstart
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using implements instead of extends
Using wrong method name
5fill in blank
hard

Fill all three blanks to create a simple interface and a class that implements it.

Java
public interface [1] {
    void [2]();
}

public class Car implements [3] {
    public void start() {
        System.out.println("Car started");
    }
}
Drag options to blanks, or click blank then click option'
AVehicle
Bstart
DEngine
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using class names instead of interface names
Mismatch between interface and implemented method names