Here is the sample code for a possible implementation of a


Here is the sample code for a possible implementation of a Bicycle class that illustrates inheritance: 

public class Bicycle {
    // the Bicycle class has
    // three fields
    public int cadence;
    public int gear;
    public int speed;

    // the Bicycle class has
    // one constructor
public Bicycle(int startCadence,
                   int startSpeed,
                   int startGear) {
        gear = startGear;
        cadence = startCadence;
        speed = startSpeed;
    }
        
    // the Bicycle class has
    // four methods
    public void setCadence(int newValue) {
        cadence = newValue;
    }
        
    public void setGear(int newValue) {
        gear = newValue;
    }
        
    public void applyBrake(int decrement) {
        speed -= decrement;
    }
        
    public void speedUp(int increment) {
        speed += increment;
    }

        
    // the Bicycle class has
    // three fields
    public int cadence;
    public int gear;
    public int speed;
        
    // the Bicycle class has
    // one constructor
    public Bicycle(int startCadence,
                   int startSpeed,
                   int startGear) {
        gear = startGear;
        cadence = startCadence;
        speed = startSpeed;
    }
        
    // the Bicycle class has
    // four methods
    public void setCadence(int newValue) {
        cadence = newValue;
    }
        
    public void setGear(int newValue) {
        gear = newValue;
    }
        
    public void applyBrake(int decrement) {
        speed -= decrement;
    }
        
    public void speedUp(int increment) {
        speed += increment;
    }
        
}

Discuss with your classmates an example of an object or concept where the concept of inheritance can be utilized. Describe what can be used as the fields, constructor and methods.  Address these questions during your discussion, and think of other questions to ask your classmates.

Hi Ashish, This is me again. So this one is just a discussion. Every week we write something on the discussion board according to the teacher's format. And this one is today's discussion topic. Let me know if you have any question.

Solution Preview :

Prepared by a verified Expert
Other Subject: Here is the sample code for a possible implementation of a
Reference No:- TGS02484898

Now Priced at $20 (50% Discount)

Recommended (96%)

Rated (4.8/5)