1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

1 Inheritance Classes and Subclasses Or Extending a Class.
OO Programming in Java Objectives for today: Constructors Method Overriding & Overloading Encapsulation.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
OOP: Inheritance By: Lamiaa Said.
CS 211 Inheritance AAA.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Inheritance Reserved word protected Reserved word super
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Inheritance Polymorphism Briana B. Morrison CSE 1302C Spring 2010.
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
INF 523Q Chapter 7: Inheritance. 2 Inheritance  Another fundamental object-oriented technique is called inheritance, which enhances software design and.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Computer Science I Inheritance Professor Evan Korth New York University.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
CS442: ADVANCED PROGRAMMING USING JAVA Lab 6: Classes and objects Computer Science Department.
Outline Creating Subclasses Overriding Methods Class Hierarchies Visibility Designing for Inheritance Inheritance and GUIs The Timer Class Copyright ©
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Coming up: Inheritance
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.4 Constructors, Overloading,
November 27, 2001Lecture 231  Previous Lecture: Parameter passing Method overloading  Today’s Lecture: Introduction to inheritance Class diagrams and.
Java Software Solutions Lewis and Loftus Chapter 8 Copyright 1997 by John Lewis and William Loftus. All rights reserved. 1 Inheritance -- Introduction.
© 2004 Pearson Addison-Wesley. All rights reserved April 10, 2006 Inheritance (part 2) ComS 207: Programming I (in Java) Iowa State University, SPRING.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Inheritance.
Lecture 12 Inheritance.
Advanced Programming in Java
An Introduction to Inheritance
Road Map Inheritance Class hierarchy Overriding methods Constructors
Week 8 Lecture -3 Inheritance and Polymorphism
CSC 113 Tutorial QUIZ I.
The super Reference Constructors cannot be used in child classes, even though they have public visibility Yet we often want to use the parent's constructor.
CSC 113: Computer programming II
Inheritance, Polymorphism, and Interfaces. Oh My
Advanced Programming Behnam Hatami Fall 2017.
Java Programming, Second Edition
Chapter 10: Method Overriding and method Overloading
Method Overriding and method Overloading
C++ Programming CLASS This pointer Static Class Friend Class
Final and Abstract Classes
Unit-1 Introduction to Java
Inheritance and Polymorphism
Presentation transcript:

1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013

Outline Review Quiz CPSC 233, winter

Key Concepts Advanced Java Copy constructor Pass by value Pass by reference Static members Inheritance Private, protected, public Member inheritance Method overriding v.s method overloading Invoking of the constructors CPSC 233, winter

4

5

6 Is the toString() method considered overloading or overriding? Is the definition of the method println(), println(String), println(int), etc… considered overloading or overriding? If you have multiple constructors in the same class with different arguments, is it considered overloading or overriding?

Constructor Invoking The non-argument constructor automatically calls the super class constructor which calls its super class constructor up to the class object constructor If you want to call a constructor in the super class use: super(……) CPSC 233, winter

8 UML Diagram (source code in practice1/) Parent - secret:int # familySecret:int + num:int + Parent() + method() + update() + toString():String Child1 - num1:int # num2:int + count:int + Child1() + method() + toString():String Child2 - num1:int # num2:int + Child2() + Child2(obj:Child2) + update() + update(n:int) + update(obj:Child1) + toString():String Answer the following questions based on the given program What are the data members that Child1 inherits from the superclass? What are the methods that Child1 inherits from the superclass? Identify method overriding in this program Identify method overloading in this program What is the output of the program (see Driver.java)?

9 UML Diagram (source code in practice2/) GrandParent - secret:int # familySecret:int + num:int + GrandParent() + method() + update() + toString():String Child1 - num1:int + count:int + Child1() + Child1(obj:Child1) + method() + update(obj:Child1) + toString():String Parent - num1:int # num2:int + Parent() + update() + update(n:int) + toString():String Answer the following questions based on the given program What are the data members that Child1 inherits from the superclass(es)? What are the methods that Child1 inherits from the superclass(es)? What are the data members that Parent inherits from the superclass? What are the methods that Parent inherits from the superclass? Identify method overriding in this program Identify method overloading in this program What is the output of the program (see Driver.java)?

Outline Review Quiz CPSC 233, winter