{"id":397,"date":"2007-10-21T00:00:00","date_gmt":"2007-10-21T00:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=397"},"modified":"2007-10-21T00:00:00","modified_gmt":"2007-10-21T00:00:00","slug":"Classes","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=397","title":{"rendered":"Classes"},"content":{"rendered":"<p><DIV><br \/>\n<DIV id=PageTitle>Classes<\/DIV><br \/>\n<BLOCKQUOTE><!---Classes--->The introduction to object-oriented concepts in the lesson titled <A class=TutorialLink href=\"http:\/\/www.strongd.net\/blog\/show\/390\" target=_top>Object-oriented Programming Concepts <\/A>used a bicycle class as an example, with racing bikes, mountain bikes, and tandem bikes as subclasses. Here is sample code for a possible implementation of a <CODE>Bicycle<\/CODE> class, to give you an overview of a class declaration. Subsequent sections of this lesson will back up and explain class declarations step by step. For the moment, don`t concern yourself with the details.<br \/>\n<BLOCKQUOTE><PRE>public class Bicycle {<BR>    \/\/ <B>the Bicycle class has three <I>fields<BR><\/I><\/B>    public int cadence;<BR>    public int gear;<BR>    public int speed;<BR>    \/\/ <B>the Bicycle class has one <I>constructor<BR><\/I><\/B>    public Bicycle(int startCadence, int startSpeed, int startGear) {<BR>        gear = startGear;<BR>        cadence = startCadence;<BR>        speed = startSpeed;<BR>    }<BR>    \/\/ <B>the Bicycle class has four <I>methods<BR><\/I><\/B>    public void setCadence(int newValue) {<BR>        cadence = newValue;<BR>    }<BR>    public void setGear(int newValue) {<BR>        gear = newValue;<BR>    }<BR>    public void applyBrake(int decrement) {<BR>        speed -= decrement;<BR>    }<BR>    public void speedUp(int increment) {<BR>        speed += increment;<BR>    }<BR>}<\/PRE><\/BLOCKQUOTE><br \/>\n<P>A class declaration for a <CODE>MountainBike<\/CODE> class that is a subclass of <CODE>Bicycle<\/CODE> might look like this: <\/P><br \/>\n<BLOCKQUOTE><PRE>public class MountainBike extends Bicycle {<BR>    \/\/ <B>the MountainBike subclass has one <I>field<BR><\/I><\/B>    public int seatHeight;<BR>    \/\/ <B>the MountainBike subclass has one <I>constructor<BR><\/I><\/B>    public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) {<BR>        super(startCadence, startSpeed, startGear);<BR>        seatHeight = startHeight;<BR>    }<BR>    \/\/ <B>the MountainBike subclass has one <I>method<BR><\/I><\/B>    public void setHeight(int newValue) {<BR>        seatHeight = newValue;<BR>    }<BR>}<\/PRE><\/BLOCKQUOTE><CODE>MountainBike<\/CODE> inherits all the fields and methods of <CODE>Bicycle<\/CODE> and adds the field <CODE>seatHeight<\/CODE> and a method to set it (mountain bikes have seats that can be moved up and down as the terrain demands). <\/BLOCKQUOTE><\/DIV><br \/>\n<DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Classes The introduction to object-oriented concepts in the lesson titled Object-oriented Programming Concepts used a bicycle class as an example, with racing bikes, mountain bikes, and tandem bikes as subclasses. Here is sample code for a possible implementation of a Bicycle class, to give you an overview of a class declaration. Subsequent sections of this &hellip; <a href=\"https:\/\/www.strongd.net\/?p=397\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Classes<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-397","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=397"}],"version-history":[{"count":0,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/397\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}