tailieunhanh - Lecture Java methods: Object-oriented programming and data structures (3rd AP edition): Chapter 12 - Maria Litvin, Gary Litvin
Chapter 12 - Arrays. This chapter’s objectives are to: Learn about arrays and when to use them, learn the syntax for declaring and initializing arrays and how to access array’s size and elements, learn about the class, discuss “for each” loops, learn simple array algorithms, understand two-dimensional arrays. | Class Hierarchies and Interfaces Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 3rd AP edition 12- Class hierarchies is the heart of OOP. Objectives: Understand class hierarchies and polymorphism Learn about abstract classes Learn the syntax for calling superclass’s constructors and methods Understand interfaces 12- Inheritance Inheritance represents the IS-A relationship between objects: an object of a subclass IS-A(n) object of the superclass. Superclass (Base class) Subclass (Derived class) Subclass extends Superclass 12- A subclass inherits all the fields and methods of its superclass, but not the constructors. Class Hierarchies Using inheritance, a programmer can define a hierarchy of classes. 12- Class Hierarchies (cont’d) Help reduce duplication of code by factoring out common code from similar classes into a common superclass. . | Class Hierarchies and Interfaces Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 3rd AP edition 12- Class hierarchies is the heart of OOP. Objectives: Understand class hierarchies and polymorphism Learn about abstract classes Learn the syntax for calling superclass’s constructors and methods Understand interfaces 12- Inheritance Inheritance represents the IS-A relationship between objects: an object of a subclass IS-A(n) object of the superclass. Superclass (Base class) Subclass (Derived class) Subclass extends Superclass 12- A subclass inherits all the fields and methods of its superclass, but not the constructors. Class Hierarchies Using inheritance, a programmer can define a hierarchy of classes. 12- Class Hierarchies (cont’d) Help reduce duplication of code by factoring out common code from similar classes into a common superclass. Balloon Constructors Accessors distance move setRadius isInside isOnBorder draw RoundBalloon Constructor draw (redefined) OvalBalloon Constructor distance (redefined) draw (redefined) 12- If two classes share a lot of code, it makes sense to define a common superclass and factor out common code into it. Class Hierarchies (cont’d) Help reduce duplication of code by letting you write more general methods in client classes. public void add (RoundBalloon b) { (b); } public void add (OvalBalloon b) { (b); } public void add (Balloon b) { (b); } Works for a any kind of Balloon 12- So inheritance helps to eliminate duplicating code in two ways: (1) by factoring out common code and (2) by writing more general methods. Abstract Classes Some of the methods in a class can be declared abstract and left with only signatures defined A class with one or more abstract methods must be declared abstract public abstract class Balloon { . public abstract void .
đang nạp các trang xem trước