chapter 6 classes & objects. learning java through alice 2 © daly and wrigley class a class...

7
Chapter 6 Classes & Objects

Upload: melvyn-hopkins

Post on 21-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 6 Classes & Objects. Learning Java through Alice 2 © Daly and Wrigley Class A class defines a particular kind of object. Each class is a blueprint

Chapter 6

Classes & Objects

Page 2: Chapter 6 Classes & Objects. Learning Java through Alice 2 © Daly and Wrigley Class A class defines a particular kind of object. Each class is a blueprint

Learning Java through Alice 2© Daly and Wrigley

Class•A class defines a particular kind of object.•Each class is a blueprint that tells Alice exactly how to

create and display an object.•Classes begin with a capital letter.

Page 3: Chapter 6 Classes & Objects. Learning Java through Alice 2 © Daly and Wrigley Class A class defines a particular kind of object. Each class is a blueprint

Learning Java through Alice 3© Daly and Wrigley

Objects

•When an object is created and displayed, we call this instantiating the class because an object is an instance of that class.

•Object names begin with a lowercase letter.

Page 4: Chapter 6 Classes & Objects. Learning Java through Alice 2 © Daly and Wrigley Class A class defines a particular kind of object. Each class is a blueprint

Learning Java through Alice 4© Daly and Wrigley

Object-Oriented Programming Concepts • Encapsulation - lets you create a program (class) that

describes data and methods that you want to use as a template to create objects. 

• Inheritance - enables you to create a class that is similar to a previously defined class, but one that still has some of its own properties. 

• Polymorphism – allows you to create new objects that perform the same methods as the base object but which perform one or more of these functions in a different way.  ▫ Overloading▫ Overriding

Page 5: Chapter 6 Classes & Objects. Learning Java through Alice 2 © Daly and Wrigley Class A class defines a particular kind of object. Each class is a blueprint

Learning Java through Alice 5© Daly and Wrigley

Declaring Objects

•Cow cow1 = new Cow ( ……..);•Adult emily = new Adult ( …..);•Button clearButton = new Button ( );

Page 6: Chapter 6 Classes & Objects. Learning Java through Alice 2 © Daly and Wrigley Class A class defines a particular kind of object. Each class is a blueprint

Learning Java through Alice 6© Daly and Wrigley

Constructor

•A constructor is a method with the same name as the class (including case sensitivity).  

•A class can contain several constructors to provide a variety of means for initializing objects of that class.  MyFishy nemo =  new MyFishy( );

public MyFishy( ) { }

Page 7: Chapter 6 Classes & Objects. Learning Java through Alice 2 © Daly and Wrigley Class A class defines a particular kind of object. Each class is a blueprint

Learning Java through Alice 7© Daly and Wrigley

Alice Setters and Getters