Chapter 9 Classes Objects 2 Objectives Explain encapsulation
Chapter 9 Classes & Objects
2 Objectives • Explain encapsulation. • Explain the purpose of inheritance. • Explain the purpose of overriding and overloading. • Create and explain the use of constructors. • Use setter and getter methods. • Create a basic UML diagram. • Create a program that inherits properties from another program. Copyright © 2018 Daly & Wrigley
3 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. Copyright © 2018 Daly & Wrigley
4 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. Copyright © 2018 Daly & Wrigley
5 Object-Oriented Programming Concepts • Encapsulation - lets you create a class template for creating objects. It is the process of hiding the attributes of a class and making them accessible via the object’s methods. • 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 Copyright © 2018 Daly & Wrigley
6 Declaring Objects • Cow cow 1 = new Cow ( ……. . ); • Adult emily = new Adult ( …. . ); • Button clear. Button = new Button ( ); Copyright © 2018 Daly & Wrigley
7 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. My. Fishy nemo = new My. Fishy( ); public My. Fishy( ) { } Copyright © 2018 Daly & Wrigley
8 Alice Setters and Getters Copyright © 2018 Daly & Wrigley
9 Unified Modeling Language (UML) Copyright © 2018 Daly & Wrigley
10 Class Template Copyright © 2018 Daly & Wrigley
11 Application to Run Class Template Copyright © 2018 Daly & Wrigley
- Slides: 11