Advanced Java Programming

Slides:



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

Chapter 1 Inheritance University Of Ha’il.
Reusable Classes.  Motivation: Write less code!
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.
Inheritance Inheritance Reserved word protected Reserved word super
ITEC200 – Week03 Inheritance and Class Hierarchies.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
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.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
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.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Inheritance using Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
Tutorial 5 Superclasses, Subclasses and Inheritance.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 9 - Inheritance.
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 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.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
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.
Coming up: Inheritance
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
© 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.
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.
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.
A Introduction to Computing II Lecture 3: Interfaces and Inheritance Fall Session 2000.
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: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Review for Test2. Scope 8 problems, 60 points. 1 Bonus problem (5 points) Coverage: – Test 1 coverage – Exception Handling, Switch Statement – Array of.
Object Oriented Programming: Inheritance
Programming in Java: lecture 7
Class Inheritance Part I
Sections Inheritance and Abstract Classes
Lecture 12 Inheritance.
Python First Edition STARTING OUT WITH Chapter 10 Inheritance
Interface, Subclass, and Abstract Class Review
Inheritance and Polymorphism
One class is an extension of another.
Week 4 Object-Oriented Programming (1): Inheritance
An Introduction to Inheritance
Road Map Inheritance Class hierarchy Overriding methods Constructors
Advanced Java Programming
Chapter 10 Thinking in Objects
CSC 205 Java Programming II
One class is an extension of another.
MSIS 670 Object-Oriented Software Engineering
ITEC324 Principle of CS III
Inheritance, Polymorphism, and Interfaces. Oh My
Advanced Java Programming
Chapter 11 Inheritance and Polymorphism
Java Programming, Second Edition
Java Inheritance.
Law firm employee analogy
Inheritance.
Inheritance and Polymorphism
C++ Programming CLASS This pointer Static Class Friend Class
Chapter 11 Inheritance and Polymorphism Part 1
Agenda Inheritance Polymorphism Type compatibility Homework.
ITEC324 Principle of CS III
Chapter 6 Inheritance.
Computer Science II for Majors
Presentation transcript:

Advanced Java Programming Session #, Speaker Name Advanced Java Programming CSS446 Spring 2014 Nan Wang 08/24/11

Chapter Goals To learn about inheritance To implement subclasses that inherit and override superclass methods

Inheritance Hierarchies Inheritance is a relationship between a more general class (called the super­class) and a more specialized class (called the subclass).

Inheritance Hierarchies The subclass inherits data and behavior from the superclass. You can always use a subclass object in place of a superclass object. E.g. void processVehicle(Vehicle v) Because Car is a subclass of Vehicle, you can call that method with a Car object: Car myCar = new Car(. . .); processVehicle(myCar);

Example

Implementing Subclasses Subclass inherits all methods that it does not override.

choiceQuestion.setAnswer("2"); question.addChoice("Canada", true); setAnswer(choiceString);

Implementing Subclasses Override: Subclass can override a superclass method by providing a new implementation. An overriding method can extend or replace the  functionality of the superclass method. Display the question text. Display the answer choices.

Override display() in subclass Display the question text. Display the answer choices. Use the reserved word super to call a superclass method

Constructor with Superclass Initializer

Override vs. Overload

Program Assignment 2

Program Assignment 2 Due Date: 1/30/2014 Submit to usm.java@gmail.com P1: 100 points Bonus: P2: 20 points and P3 30 points