1 / 7

Head First Java – Ch. 2

Head First Java – Ch. 2. Classes v. Objects. Page 34. What is a Class? – 2 major pieces Things that the Class Knows – Instance Variables Things that the Class Does – Methods Television Class – specific Manufacturer; size; color; pixel quality Television Method

ohio
Download Presentation

Head First Java – Ch. 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Head First Java – Ch. 2 Classes v. Objects

  2. Page 34 • What is a Class? – 2 major pieces • Things that the Class Knows – Instance Variables • Things that the Class Does – Methods • Television Class – specific • Manufacturer; size; color; pixel quality • Television Method • Turn on, play a show or movie, turn off; adjust sound, etc.

  3. Page 35 • Difference between a class and an object • A class is not an object. (but it’s used to construct them. • A class is a blueprint for an object • Tells the virtual machine how to make an object of that particular type • Example – a Dog – Dog Class – a blueprint that the dog objects will be made from • Methods – all dogs bark, drink, eat, poop, etc.

  4. Examples • Rolodex cards – • Each has blank fields • Blueprint for a house - class • Object – houses built from blueprint.

  5. Page 36 – Making your 1st Object • Dog Class – instance variables and a method • TestDrive class- will have main method – runs program • Class has instance variables and methods • At top of class you declare the variables • Next, create a method – thing the dog can do • In TestDrive; create a new Dog object • Dog d = new Dog(); //makes a dog object • d.size = 40; // uses dot operator to set size of dog. • d.bark(); //calls the bark method • The Dot Operator – page 36

  6. Code the class and object All of the classes that you create objects from need to get compiled first. In example, dog class compiled first, then DogTestDrive. Dog class won’t run on it’s own – no main method Need to execute the class with the main method The method that runs is the Bark method

  7. YouTube Demo • We will look at demo of code on LTC’s video

More Related