Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the.

Slides:



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

Reusable Classes.  Motivation: Write less code!
Inheritance Writing and using Classes effectively.
OOP: Inheritance By: Lamiaa Said.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Comp 249 Programming Methodology Chapter 7 - Inheritance – Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
 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.
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.
CS102--Object Oriented Programming Lecture 7: – Inheritance Copyright © 2008 Xiaoyan Li.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Lecture 10: Inheritance Subclasses and superclasses The inheritance chain Access control The Object cosmic superclass The super keyword Overriding methods.
26-Jun-15 Polymorphism. 2 Legal assignments Widening is legal Narrowing is illegal (unless you cast) class Test { public static void main(String args[])
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Slides prepared by Rose Williams, Binghamton University Chapter 7 Inheritance.
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 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Inheritance using Java
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
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.
MCQ The special syntax for invoking a constructor of the base class is: a)super() b)base() c)parent() d)child() 1 Correct Answer = A super();
What is inheritance? It is the ability to create a new class from an existing class.
28-Dec-04polymorhism.ppt1 Polymorphism. 28-Dec-04polymorhism.ppt2 signatures in any programming language, a signature is what distinguishes one function.
Parameters… Classes Cont Mrs. C. Furman October 13, 2008.
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.
Inheritance and Access Control CS 162 (Summer 2009)
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Object Oriented Programming
Creating Classes from Other Classes Appendix D © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.4 Constructors, Overloading,
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.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 6 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Class Inheritance Part I
OOP: Encapsulation &Abstraction
Inheritance and Polymorphism
Java Unit 11: Inheritance I
Lecture 10: Inheritance Subclasses and superclasses
An Introduction to Inheritance
Inheritance, Polymorphism, and Interfaces. Oh My
Advanced Java Programming
Comp 249 Programming Methodology
Inheritance, Polymorphism, and Interfaces. Oh My
Inherited Classes in Java
Java – Inheritance.
Chapter 11 Inheritance and Polymorphism
Recitation 7 October 7, 2011.
Java Programming, Second Edition
Java Inheritance.
Chapter 10: Method Overriding and method Overloading
Notes from Week 5 CSE 115 Spring 2006 February 13, 15 & 17, 2006.
Method Overriding and method Overloading
C++ Programming CLASS This pointer Static Class Friend Class
Chapter 11 Inheritance and Polymorphism Part 1
Presentation transcript:

Inheritance Review/Recap

ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the behavior from the subclass that the superclass had.

ClassA extends ClassB When the constructor from ClassA is called, it automatically calls the no- argument constructor for ClassB. If ClassB does not have a no-argument constructor, ClassA must explicitly call one of the other constructors from ClassB using the keyword super.

ClassA extends ClassB A subclass is the specialization of the superclass, so we can add instance variables, add methods, change parameters on methods, or change the way methods behave.

ClassA extends ClassB When we have a method that has the same signature in a subclass as one in the superclass, we have method overriding. Method overriding is how we change the behaviors of methods in a subclass.

Inheritance Looking at inheritance in reverse – if we have a lot of commonality amongst some classes, we can create one superclass to generalize amongst the subclasses. Ex) Got a lot of classes that do the same thing? Create a common superclass!

What’s the difference? Method overloading Method inheritance Method overriding