1 / 13

Principles of Computer Programming (using Java) Chapter 10 Subclasses

Principles of Computer Programming (using Java) Chapter 10 Subclasses. Haidong Xue Summer 2011, at GSU. Content. Inheritance Overriding Polymorphism The “Object” class. Inheritance. What is inheritance? What are the advantages of inheritance in Java?

menefer
Download Presentation

Principles of Computer Programming (using Java) Chapter 10 Subclasses

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. Principles of Computer Programming(using Java)Chapter 10 Subclasses Haidong Xue Summer 2011, at GSU

  2. Content • Inheritance • Overriding • Polymorphism • The “Object” class

  3. Inheritance • What is inheritance? • What are the advantages of inheritance in Java? • How to make a class in Java using inheritance? • E.g.: • TestInheritance.java, Vehicle.java, Car.java, Bike.java

  4. Inheritance Car Data: speed, weight, gas amount, size of tires Actions: show speed, show weight, accelerate, brake, add gas, show tire size

  5. Inheritance Bike Data: speed, weight, size of tires, size of pedals Actions: show speed, show weight, accelerate, brake, show tire size, show pedal size

  6. Inheritance Car Bike Data: speed, weight, gas amount, size of tires Actions: show speed, show weight, accelerate, brake, add gas, show tire size Data: speed, weight, size of tires, size of pedals Actions: show speed, show weight, accelerate, brake, show tire size, show pedal size

  7. Inheritance Data: speed, weight, size of tires Actions: show speed, show weight, accelerate, brake, show tire size Vehicle extends Car Data: gas amount Actions: add gas Bike Data: size of pedals Actions: show pedal size

  8. Inheritance • TestInheritance.java • Vehicle.java • Car.java • Bike.java

  9. Overriding • If a method in the subclass has the same signature of a method in the superclass, the method in the superclass is hided and overridden. • E.g.: • TestOverriding.java • Vehicle.java, Car.java, Bike.java

  10. Polymorphism • An ability of a programming language; • an instance of a subclass can take the placeof an instance of any of its superclasses; • if an object variable of the superclass points to a subclass object, when calling an overridden method, the method of the subclass will be called.

  11. The punch game • InstructorsInCSC2310.java

  12. The Object class • What is Object class? • A rule: all the classes have to have a superclass. • The Object class is the default superclass. • What are the advantages? • One type for all; • Some common method for all the objects, like toString().

  13. The bonus assignment • Worth: 10 points in the final grade • Develop a program to play Texas Holdem Poker

More Related