What is an“ Object An object is a thing that we teach to the computer, so that the computer knows what the thing is Unlike people, a computer cannot see, feel and smell. It can only read codes. We have to define objects(or things)by describing the objects using (programming) languages The way we describe a thing is composed of two parts o Attributes(variables, properties ) What an object has o Methods: what an object can do
What is an “Object” • An object is a thing, that we teach to the computer, so that the computer knows what the thing is • Unlike people, a computer cannot see, feel and smell. It can only read codes. We have to define objects (or things) by describing the objects using (programming) languages. • The way we describe a thing is composed of two parts o Attributes (variables, properties): what an object has o Methods: what an object can do 6
Bicycle Music Music Player
7 Bicycle Music Music Player
Example: Bicycle Define the object for computers by specifying o The properties the object has o The functions the object provides Attributes Method o cadence o set cadence o gear o set the gear o speed o speed up o brake
Example: Bicycle 8 • Attributes: o cadence o gear o speed • Method: o set cadence o set the gear o speed up o brake • Define the object for computers by specifying o The properties the object has o The functions the object provides
package com. example test; //A bicycle class Example taken from Oracle Docs public class Bicycle t public int cadence; public int gear public int speed public Bicycle(int startCadence, int startspeed, int startGear) gear startGearj cadence startCadence; speed startspeed public void setCadence(int newValue)t cadence newValue public void setGear(int newValue)i gear newvaluej public void apply Brake(int decrement )i speed - decrement Bicycle public void speedUp(int increment)t speed + increment;
9 Bicycle
package com. example test; //A bicycle class Example taken from Oracle Docs public class Bicycle t Bicycle Class o can be thought of as a template, a prototype or a blueprint of an object o is the fundamental structure in object-oriented programming 10
10 Class o can be thought of as a template, a prototype or a blueprint of an object o is the fundamental structure in object-oriented programming Bicycle