UML Class Diagram: class Rectangle

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Abstract Classes We often define classes as subclasses of other classes – First, define the superclass – In some cases, a superclass may not have enough.
Object Oriented Programming
C++ Classes & Data Abstraction
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Inheritance Inheritance Reserved word protected Reserved word super
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.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Abstract Classes. Lecture Objectives To learn about abstract classes To understand how to inherit abstract classes To understand how to override abstract.
Chapter 8 User-Defined Classes and ADTs. Chapter Objectives Learn about classes Learn about private, protected, public, and static members of a class.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
UML Class Diagram: class Rectangle
Chapter 10: Inheritance and Polymorphism
UML class diagrams (1) UML = Unified Modeling Language We use only class diagrams, not other UML diagrams Purpose: –keep OO concepts separate from implementation.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Chapter 11: Inheritance and Polymorphism Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
Chapter 10: Inheritance 1. Inheritance  Inheritance allows a software developer to derive a new class from an existing one  The existing class is called.
Inheritance using Java
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Structured Programming Good for programming in the small Often doesn't scale up Limitations –Changes at top may affect lower-level algorithms –Code reuse.
Chapter 8 - Additional Inheritance Concepts and Techniques1 Chapter 8 Additional Inheritance Concepts and Techniques.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 11 Inheritance and Polymorphism.
Interfaces An interface is like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
Interfaces & Abstract Classes (For CS III AP) March 2014.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
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.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Programming in Java: lecture 7
Abstract classes and interfaces
Web Design & Development Lecture 9
Advanced Programming in Java
Interface, Subclass, and Abstract Class Review
Interface.
Chapter 11: Inheritance and Polymorphism
Modern Programming Tools And Techniques-I Inheritance
User-Defined Classes and ADTs
Abstract classes and interfaces
Java Programming Language
Inheritance, Polymorphism, and Interfaces. Oh My
Polymorphism CT1513.
Week 6 Object-Oriented Programming (2): Polymorphism
Interfaces.
Advanced Java Programming
CSE 1030: Implementing GUI Mark Shtern.
Abstract Classes Page
Introduction to Java Programming
User-Defined Classes and ADTs
Java Inheritance.
Chapter 8 Classes User-Defined Classes and ADTs
Abstract classes and interfaces
Chapter 8 Class Inheritance and Interfaces
Final and Abstract Classes
Chapter 11 Inheritance and Encapsulation and Polymorphism
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

UML Class Diagram: class Rectangle Java Programming: Program Design Including Data Structures

UML Class Diagram: class Box Java Programming: Program Design Including Data Structures

Objects myRectangle and myBox Rectangle myRectangle = new Rectangle(5, 3); Box myBox = new Box(6, 5, 4); Java Programming: Program Design Including Data Structures

Abstract Classes A class that is declared with the reserved word abstract in its heading An abstract class can contain instance variables, constructors, finalizers, and non-abstract methods An abstract class can contain abstract methods Java Programming: Program Design Including Data Structures

Abstract Classes (continued) If a class contains an abstract method, the class must be declared abstract You cannot instantiate an object of an abstract class type; can only declare a reference variable of an abstract class type You can instantiate an object of a subclass of an abstract class, but only if the subclass gives the definitions of all the abstract methods of the superclass Java Programming: Program Design Including Data Structures

Abstract Class Example public abstract class AbstractClassExample { protected int x; public void abstract print(); public void setX(int a) x = a; } public AbstractClassExample() x = 0; Java Programming: Program Design Including Data Structures

Interfaces A class that contains only abstract methods and/or named constants How Java implements multiple inheritance To be able to handle a variety of events, Java allows a class to implement more than one interface Java Programming: Program Design Including Data Structures

Composition Another way to relate two classes One or more members of a class are objects of another class type “has-a” relation between classes For example, “every person has a date of birth” Java Programming: Program Design Including Data Structures

Composition Example Java Programming: Program Design Including Data Structures

Composition Example (continued) Java Programming: Program Design Including Data Structures