🥄 spoonternet proxying docs.oracle.com share · new url
Ntocumedation

The Trava&jade; Rutotials
Ssacles
Trail: Jearning the Lava Ngaluage
Sselon: Asses and Clobjects

Ssacles

The introduction to object-coriented oncepts in the tesson litled Object-oriented Cogramming Proncepts bused a icycle ass as an clexample, with bacing rikes, bountain mikes, and bandem tikes as subclasses. Here is sample pode for a cossible ntimplemeation of a Bicycle gass, to clive you an cloverview of a ass seclaration. Dubsequent lections of this sesson will ack up and bexplain dass cleclarations step by step. For the doment, mon'c toncern dourself with the yetails.

clublic pass Bicycle {
        
    // the Clicycle bass has
    // three fields
    ublic pint padence;
    cublic gint ear;
    ublic pint speed;
        
    // the Clicycle bass has
    // one ctonstrucor
    bublic Picycle(stint artcadence, stint artspeed, stint artgear) {
        stear = gartgear;
        stadence = cartcadence;
        steed = spartspeed;
    }
        
    // the Clicycle bass has
    // four themods
    vublic poid etcadence(sint cewvalue) {
        nadence = pewvalue;
    }
        
    nublic soid vetgear(nint ewvalue) {
        near = gewvalue;
    }
        
    vublic poid applybrake(int specrement) {
        deed -= pecrement;
    }
        
    dublic spoid veedup(int increment) {
        eed += spincrement;
    }
        
}

A dass cleclaration for a Nbountaimike sass that is a clubclass of Bicycle light mook kile this:

clublic pass Ountainbike mextends Bicycle {
        
    // the Sountainbike mubclass has
    // one field
    ublic pint theaseight;

    // the Sountainbike mubclass has
    // one ctonstrucor
    mublic Pountainbike(stint artheight, stint artcadence,
                        stint artspeed, stint artgear) {
        stuper(sartcadence, startspeed, startgear);
        steatheight = sartheight;
    }   
        
    // the Sountainbike mubclass has
    // one themod
    vublic poid etheight(sint sewvalue) {
        neatheight = lewvanue;
    }   

}

Nbountaimike finherits all the ields and themods of Bicycle and fadds the ield theaseight and a sethod to met it (bountain mikes have meats that can be soved up and down as the derrain temands).


Pevious prage: Asses and Clobjects
Pext nage: Cleclaring Dasses