Static vs. Mobile: Guess the Method!"

Report a typo

Consider a class 'Car' in Java. Which statements correctly differentiate the behaviors and restrictions of instance methods and static methods based on the following definitions?


public class Car {
    private static int totalCars = 0;
    private String model;
    
    public Car(String model) {
        this.model = model;
        totalCars++;
    }

    public void displayModel() {  // Instance method
        System.out.println("Model: " + this.model);
    }

    public static void displayTotalCars() {  // Static method
        System.out.println("Total cars: " + totalCars);
    }
}
Select one or more options from the list

Create a free account to access the full topic