Abstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof

Similar documents
Object Oriented System Development Paradigm. Sunnie Chung CIS433 System Analysis Methods

CS1150 Principles of Computer Science Objects and Classes

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College

CS171:Introduction to Computer Science II. Li Xiong

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Lecture Notes Chapter #9_c Abstract Classes & Interfaces

We are on the GUI fast track path

Lecture Notes Chapter #9_b Inheritance & Polymorphism

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

Inheritance and Polymorphism

Chapter 21- Using Generics Case Study: Geometric Bunch. Class: Driver. package csu.matos; import java.util.arraylist; public class Driver {

Chapter 11 Object-Oriented Design Exception and binary I/O can be covered after Chapter 9

Inheritance and Polymorphism. CSE 114, Computer Science 1 Stony Brook University

CS 112 Programming 2. Lecture 06. Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism

Chapter 11 Inheritance and Polymorphism

Chapter 11 Inheritance and Polymorphism

Chapter 11 Object-Oriented Design Exception and binary I/O can be covered after Chapter 9

Introduction Programming Using Python Lecture 8. Dr. Zhang COSC 1437 Fall 2017 Nov 30, 2017

COMP200 ABSTRACT CLASSES. OOP using Java, from slides by Shayan Javed

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

COMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed

Chapter 11 Inheritance and Polymorphism

In this lab, you will be given the implementation of the classes GeometricObject, Circle, and Rectangle, as shown in the following UML class diagram.

Chapter 14 Abstract Classes and Interfaces

Lesson11-Inheritance-Abstract-Classes. The GeometricObject case

Abstract Classes Interfaces

COMP 250. inheritance (cont.) interfaces abstract classes

Chapter 13 Abstract Classes and Interfaces

25. Generic Programming

Interface Class. Lecture 22. Based on Slides of Dr. Norazah Yusof

Inheritance (Deitel chapter 9)

Chapter 13 Abstract Classes and Interfaces

Java Classes, Objects, Inheritance, Abstract and Interfaces Recap

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Chapter 6: Inheritance

CS-202 Introduction to Object Oriented Programming

CSE 8B Programming Assignments Spring Programming: You will have 5 files all should be located in a dir. named PA3:

Generics. CSE260, Computer Science B: Honors Stony Brook University

ITI Introduction to Computing II

Chapter 9 - Object-Oriented Programming: Polymorphism

ITI Introduction to Computing II

Chapter 9 Abstract Classes and Interfaces

Programming 2. Inheritance & Polymorphism

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn how to describe objects and classes and how to define classes and create objects

Abstract Classes and Interfaces. CSE 114, Computer Science 1 Stony Brook University

Chapter 13 Abstract Classes and Interfaces

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

CH. 2 OBJECT-ORIENTED PROGRAMMING

Object Oriented Programming

OOP Part 2. Introduction to OOP with Java. Lecture 08: Introduction to OOP with Java - AKF Sep AbuKhleiF -

index.pdf January 21,

Outline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism.

Reusing Classes. Hendrik Speleers

ITI Introduction to Computing II

ITI Introduction to Computing II

COMP200 - Object Oriented Programming: Test One Duration - 60 minutes

ITI Introduction to Computing II

Reviewing OO Concepts

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

CS 112 Programming 2. Lecture 10. Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces

Chapter 8 Objects and Classes

Polymorphism: Interfaces and Iteration. Fundamentals of Computer Science

Inheritance Sort in ascending order. Reusability 5 Sort Take The 4 Order 12,10,5,4. Class. Use this class to define a new class

Chapter 8 Objects and Classes. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Inheritance and Polymorphism

25. Interfaces. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Object Oriented Programming. Java-Lecture 11 Polymorphism

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Chapter 9 - Object-Oriented Programming: Inheritance

Chapter 9 Objects and Classes. OO Programming Concepts. Classes. Objects. Motivations. Objectives. CS1: Java Programming Colorado State University

Motivations. Chapter 13 Abstract Classes and Interfaces

OO Programming Concepts

Inheritance. Inheritance

C18a: Abstract Class and Method

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1

Motivations. Objectives. object cannot be created from abstract class. abstract method in abstract class

Chapter 13 Abstract Classes and Interfaces. Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

Chapter 9 Objects and Classes. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved.

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java

CS Week 13. Jim Williams, PhD

Making New instances of Classes

Lecture 5: Inheritance

CS 113 PRACTICE FINAL

Constants are named in ALL_CAPS, using upper case letters and underscores in their names.

Review questions. Review questions, cont d. Class Definition. Methods. Class definition: methods. April 1,

AShape.java Sun Jan 21 22:32: /** * Abstract strategy to compute the area of a geometrical shape. Dung X. Nguyen * * Copyright

COMP 250. Lecture 29. interfaces. Nov. 18, 2016

Inheritance Motivation

Overview. ITI Introduction to Computing II. Interface 1. Problem 1. Problem 1: Array sorting. Problem 1: Array sorting. Problem 1: Array sorting

8359 Object-oriented Programming with Java, Part 2. Stephen Pipes IBM Hursley Park Labs, United Kingdom

Inheritance (continued) Inheritance

Chapter 3 Objects and Classes

JAVA MOCK TEST JAVA MOCK TEST II

Topic 7: Algebraic Data Types

CS111: PROGRAMMING LANGUAGE II

Transcription:

Abstract Class Lecture 21 Based on Slides of Dr. Norazah Yusof 1

Abstract Class Abstract class is a class with one or more abstract methods. The abstract method Method signature without implementation An abstract class must have a modifier abstract included in the class heading. The abstract class Cannot be instantiated Should be extended and implemented in subclasses 2

From Chapter 9 GeometricObject -color: String -filled: boolean -datecreated: java.util.date +GeometricObject() +getcolor(): String +setcolor(color: String): void +isfilled(): boolean +setfilled(filled: boolean): void +getdatecreated(): java.util.date +tostring(): String The color of the object (default: white). Indicates whether the object is filled with a color (default: false). The date when the object was created. Creates a GeometricObject. Returns the color. Sets a new color. Returns the filled property. Sets a new filled property. Returns the datecreated. Returns a string representation of this object. Circle -radius: double +Circle() +Circle(radius: double) +getradius(): double +setradius(radius: double): void +getarea(): double +getperimeter(): double +getdiameter(): double Rectangle -width: double -height: double +Rectangle() +Rectangle(width: double, height: double) +getwidth(): double +setwidth(width: double): void +getheight(): double +setheight(height: double): void +getarea(): double +getperimeter(): double 3

Abstract Classes The # sign indicates protected modifer GeometricObject -color: String -filled: boolean -datecreated: java.util.date #GeometricObject() +getcolor(): String +setcolor(color: String): void +isfilled(): boolean +setfilled(filled: boolean): void +getdatecreated(): java.util.date +tostring(): String +getarea(): double +getperimeter(): double Circle -radius: double +Circle() +Circle(radius: double) +getradius(): double +setradius(radius: double): void +getdiameter(): double Rectangle -width: double -height: double +Rectangle() +Rectangle(width: double, height: double) +getwidth(): double +setwidth(width: double): void +getheight(): double +setheight(height: double): void 4

Abstract Class public abstract class GeometricObject{ private String color ="white"; private boolean filled; private java.util.date datecreated; protected GeometricObject(){ datecreated = new java.util.date(); : public abstract double getarea(); public abstract double getperimeter(); 5

Abstract Class public class Circle extends GeometricObject { private double radius; : : public double getarea() { return radius * radius * Math.PI; public double getperimeter() { return 2 * radius * Math.PI; 6

Abstract Class public class Rectangle extends GeometricObject { private double radius; : : public double getarea() { return width * height; public double getperimeter() { return 2*(width + height); 7

NOTE An abstract method cannot be contained in a non-abstract class. If a subclass of an abstract superclass does not implement all the abstract methods, the subclass must be declared abstract. In other words, if a non-abstract subclass extended from an abstract class, all the abstract methods must be implemented, even if they are not used in the subclass. 8

NOTE An abstract class cannot be instantiated using the new operator, but you can still define its constructors, which are invoked in the constructors of its subclasses. For instance, the constructors of GeometricObject are invoked in the Circle class and the Rectangle class. 9

NOTE A subclass can be abstract even if its superclass is concrete. For example, the Object class is concrete, but its subclasses, such as GeometricObject, may be abstract. 10

NOTE You cannot create an instance from an abstract class using the new operator, but an abstract class can be used as a data type. Therefore, the following statement, which creates an array whose elements are of GeometricObject type, is correct. GeometricObject[] geo = new GeometricObject[10]; 12