Tutorial 5 Superclasses, Subclasses and Inheritance.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Constructors Method Overriding & Overloading Encapsulation.
Advertisements

CLASS INHERITANCE Class inheritance is about inheriting/deriving properties from another class. When inheriting a class you are inheriting the attributes.
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Chapter 10: Introduction to Inheritance
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
ITEC200 – Week03 Inheritance and Class Hierarchies.
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.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
Inheritance COMP53 Sept Inheritance Inheritance allows us to define new classes by extending existing classes. A child class inherits all members.
1 Chapter 7 Inheritance, Polymorphism, and Scope.
Lecture 32 Inheritance COMP1681 / SE15 Introduction to Programming.
Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Computer Science I Inheritance Professor Evan Korth New York University.
Chapter 10: Inheritance 1. Inheritance  Inheritance allows a software developer to derive a new class from an existing one  The existing class is called.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Ruby: Multiple Inheritance, Interfaces, Mixins 1.
Inheritance using Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Chapter 8 More Object Concepts
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.
1 Given the Radio class  We may define other derivative types: Cassette walkman IS-A radio Alarm clock radio IS-A radio Car radio IS-A radio.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Inheritance The Basics in Java. Definition  A class that is derived from another class is called a subclass (also a derived class, extended class, or.
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.
Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”
Inheritance comp249. Question 1 What type of inheritance does Java have? a) single inheritance b)double inheritance c) multiple inheritance d)class inheritance.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Inheritance Chapter 11 in Gaddis. Is a relationships in ‘real’ life Exist when one object is a specialized version of another one –Examples An english.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
A Introduction to Computing II Lecture 3: Interfaces and Inheritance Fall Session 2000.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
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.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Lecture 5:Interfaces and Abstract Classes
Programming in Java: lecture 7
Object-Oriented Concepts
Lecture 12 Inheritance.
One class is an extension of another.
An Introduction to Inheritance
Road Map Inheritance Class hierarchy Overriding methods Constructors
Chapter 10 Thinking in Objects
One class is an extension of another.
Advanced Java Programming
Inherited Classes in Java
Two big words Inheritance Polymorphism
Abstract Classes Page
Chapter 11 Inheritance and Polymorphism
Java Programming, Second Edition
Chapter 14 Abstract Classes and Interfaces
Presentation transcript:

Tutorial 5 Superclasses, Subclasses and Inheritance

Inheritance Classes can be derived from other classes, thereby inheriting fields and methods from those classes Subclass - derived class (Specialised) Superclass – inherited class (Generic) Basic Idea: Inherit everything from Superclass and extend its abilities

Inheritance and Constructors Every time a new Object is created, constructors are chain-call until Object Class constructor is called!

Overriding Methods Overriding: Subclass modifies the implementation of a method defined in the Superclass Car c2 = new Porsche(); c2.makeSound(); //”Porsche vroommm! Java always uses methods and variables of the more “specialised” class

MIDTERM REVIEW s.library.utoronto.ca/browse?type=subject &order=ASC&rpp=20&value=CSC207H s.library.utoronto.ca/browse?type=subject &order=ASC&rpp=20&value=CSC207H Practice the questions that seem relevant!

A1 CommaSeparatedValues (CSV) You are writing Parser/Evaluator Syntax specified by CFG OO design (CRC cards) will help you create a tree for evaluating recursively!