Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
ISE 582: Web Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 4 JAVA Cup.
Abstract Data Types and Encapsulation Concepts
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Object-Oriented Programming Chapter Chapter
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
ISBN Object-Oriented Programming Chapter Chapter
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Classes, Interfaces and Packages
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
ISBN Chapter 12 Support for Object-Oriented Programming.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
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.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Written by: Dr. JJ Shepherd
Modern Programming Tools And Techniques-I
OOP: Encapsulation &Abstraction
Objects as a programming concept
Inheritance and Polymorphism
Chapter 3: Using Methods, Classes, and Objects
Chapter 9 Inheritance and Polymorphism
Java Programming Language
Interfaces.
Java Programming, Second Edition
Inheritance and Polymorphism
Chapter 11 Inheritance and Encapsulation and Polymorphism
CSG2H3 Object Oriented Programming
Presentation transcript:

Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2

Department of Computer Science2 Last Lecture - Basic Java Introduction (Chapter 1 of Weiss) - Reference types (Chapter 2 of Weiss) - Today - Objects and References (Chapter 3 of Weiss) - Inheritance (Chapter 4 of Weiss)

Department of Computer Science3 OO-Programming Objects are atomic units that have a structure and a state  Operations are defined on an object to access and change this state Information hiding means implementation details are hidden Encapsulation means data is grouped with operations

Department of Computer Science4 What is an object? A class is a blue-print for objects  Objects are instances of a class A class has fields and methods  These are called members of the class  Values of the fields define an object’s state  Methods are used to access and change state Public members are visible outside the class, private members are not

Department of Computer Science5 Basic Methods Constructors specify how an object is created and initialized  The default constructor initializes all fields with their default values Fields are usually private and manipulated with public accessor and mutator methods  Naming convention is get and set Static fields and methods exist once per class, unlike instance methods

Department of Computer Science6 Additional Constructs The special reference this refers to the address of the current object You can also use this in a constructor to call another constructor in the same class The instanceof operator is used to check whether a variable refers to an instance of a particular class You can use a static initializer to initialize static fields

Department of Computer Science7 Packages Larger programs are split into packages Import is used to import packages or individual classes in a package The package statement declares that a class belongs to a package  Packages must match directories in the file system Relevant packages must be in the classpath of the virtual machine

Department of Computer Science8 Inheritance Inheritance models IS-A relationship  Rather than HAS-A relationship A subclass extends a superclass A subclass can override a method  Method must have the same parameters  Return type must be same or subtype References to a superclass type are polymorphic

Department of Computer Science9 Continued IS-A relationship is transitive Protected members are visible in subclass Can use super to access superclass constructors (from subclass constructor) A class that is final cannot be extended A method that is final cannot be overriden Type of a reference variable defines what members we can access with the dot operator

Department of Computer Science10 Abstract methods and classes Abstract method does not provide any implementation (placeholder) A class with at least one abstract method must be declared abstract An interface is an abstract class that has only public abstract methods A class does not extend an interface, it implements it

Department of Computer Science11 Generic Programming Polymorphism enables us to write generic programs  Code where every reference is of type Object – extreme case Primitives are not objects Need to use wrapper classes

Department of Computer Science12 Continued Object has few methods Generic classes are parameterized types Class declaration includes one or more type parameters in angular brackets We can also have generic methods in any class