copyright by Scott GrissomCh 1 Objects and Classes Slide 1 Classes and Objects A Class refers to something in general describes a category of items a cookie cutter to create items a blueprint to build an item An Object a specific item that has unique properties (characteristics) also called an instance of a class objects are instantiated from classes objects have state and behavior Examples All cars have a color, MPG, and location My car is gray an in parking lot C All people have a height, weight and name Joe is 5’-10 and weights 150 lbs Wonder Woman is a super hero Lassie is a dog Atlas Shrugged is a book
copyright by Scott GrissomCh 1 Objects and Classes Slide 2 BlueJ Demo #1 open the Shapes project instantiate an object invoke a method provide parameters inspect an object’s state
copyright by Scott GrissomCh 1 Objects and Classes Slide 3 Methods Methods tell an object to do something “raise your hand” “stand up” start engine Some methods require parameters “step forward” - how many steps? “clap hands” - how many times? turn - which direction? Some methods return an answer “what is your name?” what is the square root of 16? return an answer how much gas is in the tank?
copyright by Scott GrissomCh 1 Objects and Classes Slide 4 Dog what are characteristics? breed hair color name weight gender what is some appropriate behavior? roll over play dead sit fetch speak
copyright by Scott GrissomCh 1 Objects and Classes Slide 5 Car what are characteristics make model color year engine what is a typical behavior start engine brake accelerate turn
copyright by Scott GrissomCh 1 Objects and Classes Slide 6 Important Concepts Data types int String boolean State - current values of all attributes Source code - text description of a class including its data fields and methods class is equivalent to a chapter methods are equivalent to paragraphs source code must compile without syntax errors Summary objects are instantiated from classes objects have state and behavior objects have methods that are invoked
copyright by Scott GrissomCh 1 Objects and Classes Slide 7 BlueJ Demo #2 open Lab-classes project create a student(s) invoke getName( ) create a LabClass enroll a student
copyright by Scott GrissomCh 1 Objects and Classes Slide 8 BlueJ Demo #3 open Picture project build a sunset method build a sunrise method