Principles of Computer Programming (using Java) Chapter 10 Subclasses Haidong Xue Summer 2011, at GSU.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Chapter 1 Inheritance University Of Ha’il.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
ITEC200 – Week03 Inheritance and Class Hierarchies.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Advanced Inheritance Concepts. In this chapter, we will cover: Creating and using abstract classes Using dynamic method binding Creating arrays of subclass.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
CSC 205 Java Programming II Polymorphism. Topics Polymorphism The principle of substitution Dynamic binding Object type casting Abstract class The canonical.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Lecture 12 March 16, The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same.
Inheritance and Access Control CS 162 (Summer 2009)
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Inheritance and Polymorphism
Java Inheritance 1/13/2015. Learning Objectives Understand how inheritance promotes software reusability Understand notions of superclasses and subclasses.
A Introduction to Computing II Lecture 3: Interfaces and Inheritance Fall Session 2000.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Object-Oriented Programming
Programming in Java: lecture 7
Sections Inheritance and Abstract Classes
OOP: Encapsulation &Abstraction
JAVA By Waqas.
Python First Edition STARTING OUT WITH Chapter 10 Inheritance
Haidong Xue Summer 2011, at GSU
Inheritance and Polymorphism
One class is an extension of another.
Java Inheritance.
Haidong Xue Summer 2011, at GSU
Haidong Xue Summer 2011, at GSU
Object Oriented Programming
Chapter 10 Thinking in Objects
One class is an extension of another.
Advanced Java Programming
Java Inheritance.
Inheritance, Polymorphism, and Interfaces. Oh My
Advanced Java Programming
Two big words Inheritance Polymorphism
Abstract Classes Page
Chapter 11 Inheritance and Polymorphism
Java Programming, Second Edition
Java Inheritance.
Object-Oriented Programming
Inheritance.
Advanced Inheritance Concepts
Inheritance and Polymorphism
Haidong Xue Summer 2011, at GSU
Haidong Xue Summer 2011, at GSU
Java Inheritance.
Principles of Computer Programming (using Java) Chapter 5 Arrays
Presentation transcript:

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? How to make a class in Java using inheritance? E.g.: – TestInheritance.java, Vehicle.java, Car.java, Bike.java

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

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

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

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

TestInheritance.java Vehicle.java Car.java Bike.java Inheritance

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

Polymorphism An ability of a programming language; an instance of a subclass can take the place of 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.

The punch game InstructorsInCSC2310.java

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().

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