I'll give a start; this is the class definition; it has one member variable, one constructor method, and another public method:
public class Car
private int no_doors;
public Car(int i) // constructor method
no_doors = i;
public int GetDoors()
Now use this class and write a small program where in Main you create 2 objects of type car using the constructor method (one with 2 and one with 4); then print the number of doors for each car using GetDoors() (you cannot access the private variable no_doors directly).© BrainMass Inc. brainmass.com March 4, 2021, 7:46 pm ad1c9bdddf
Java Programming is featured and discussed.