UML Class Diagram: class Rectangle

Slides:



Advertisements
Similar presentations
Abstract Classes We often define classes as subclasses of other classes – First, define the superclass – In some cases, a superclass may not have enough.
Advertisements

Object Oriented Programming
C++ Classes & Data Abstraction
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.
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
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.
Java 212: Inheritance and Polymorphism. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override (not.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Chapter 8 User-Defined Classes and ADTs. Chapter Objectives Learn about classes Learn about private, protected, public, and static members of a class.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
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.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
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.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
1 Abstract Classes and Interfaces. 2 The abstract Modifier  The abstract class –Cannot be instantiated –Should be extended and implemented in subclasses.
Object Oriented Programming
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.
CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Interfaces & Abstract Classes (For CS III AP) March 2014.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
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.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Web Design & Development Lecture 9
Advanced Programming in Java
Interface, Subclass, and Abstract Class Review
Interface.
Chapter 11: Inheritance and Polymorphism
UML Class Diagram: class Rectangle
Modern Programming Tools And Techniques-I Inheritance
User-Defined Classes and ADTs
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.
Introduction to Java Programming
Chapter 8 Classes User-Defined Classes and ADTs
Chapter 8 Class Inheritance and Interfaces
Final and Abstract Classes
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