Java Programming
Not what you're looking for? Search our solutions OR ask your own Custom question.
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()
{
return no_doors;
}
}
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 December 15, 2022, 6:03 pm ad1c9bdddfhttps://brainmass.com/computer-science/java/java-programming-example-121928
Solution Summary
Java Programming is featured and discussed.
$2.49