Explore BrainMass

Explore BrainMass

    Java Programming

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    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 March 4, 2021, 7:46 pm ad1c9bdddf
    https://brainmass.com/computer-science/java/java-programming-example-121928

    Solution Summary

    Java Programming is featured and discussed.

    $2.49

    ADVERTISEMENT