0
0
Javaprogramming~15 mins

Public access modifier in Java - Interactive Code Practice

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

Complete the code to declare a public 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
2fill in blank
medium

Complete the code to declare a public method named start inside the Car class.

Java
public class Car {
    public [1] start() {
        return "Car started";
    }
}
🎯 Drag options to blanks, or click blank then click option
Avoid
BString
Cint
Dboolean
Attempts:
3 left
3fill in blank
hard

Fix the error in the code by completing the access modifier for the variable speed.

Java
public class Car {
    [1] int speed;

    public void setSpeed(int s) {
        speed = s;
    }
}
🎯 Drag options to blanks, or click blank then click option
Apublic
Bprotected
Cprivate
Ddefault
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a public constructor for the Car class that sets the speed.

Java
public class Car {
    int speed;

    public [1]([2] int speed) {
        this.speed = speed;
    }
}
🎯 Drag options to blanks, or click blank then click option
ACar
Bvoid
Cint
DSpeed
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a public method named accelerate that increases speed by a given amount and returns the new speed.

Java
public class Car {
    int speed;

    public int [1](int [2]) {
        speed [3] amount;
        return speed;
    }
}
🎯 Drag options to blanks, or click blank then click option
Aaccelerate
Bamount
C+=
D-
Attempts:
3 left