Abstract methods and classes. Abstract method A placeholder for a method that will be fully defined in a subclass.

Slides:



Advertisements
Similar presentations
PHP functions What are Functions? A function structure:
Advertisements

More on Classes Inheritance and Polymorphism
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Abstract Class and Interface
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.
Programming With Java ICS 201 University Of Ha’il1 Chapter 8 Abstract Class.
CMSC 202 Inheritance. Aug 6, Object Relationships An object can have another object as one of instance variables. The Person class had two Date.
Abstract Classes and Interfaces The objectives of this chapter are: To explore the concept of abstract classes To understand interfaces To understand the.
Comp 249 Programming Methodology Chapter 7 - Inheritance – Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
Abstract Classes. Lecture Objectives To learn about abstract classes To understand how to inherit abstract classes To understand how to override abstract.
Unit 021 Abstract Classes What is an Abstract Class? Properties of an Abstract Class Discovering Abstract Classes.
CS102--Object Oriented Programming Lecture 7: – Inheritance Copyright © 2008 Xiaoyan Li.
Chapter 8 Polymorphism and Abstract Classes Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights.
CS102--Object Oriented Programming Lecture 9: – Polymorphism Copyright © 2008 Xiaoyan Li.
UML Class Diagram: class Rectangle
Chapter 10: Inheritance and Polymorphism
Slides prepared by Rose Williams, Binghamton University Chapter 7 Inheritance.
CS102--Object Oriented Programming Lecture 10: – Abstract Classes Copyright © 2008 Xiaoyan Li.
Chapter 11: Inheritance and Polymorphism Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
Inheritance using Java
COP 3003 Object-Oriented Programming - Polymorphism Dr. Janusz Zalewski, Fall 2013 Prepared by Dr Dahai Guo.
Internet Software Development Classes and Inheritance Paul J Krause.
Programming With Java ICS201 University Of Ha’il1 Chapter 8 Polymorphism and Abstract Classes.
Method signature Name and parameter list public static void test() public static int test() => Syntax error, Duplicate method test You cannot declare more.
Inheritance CSC 171 FALL 2004 LECTURE 18. READING Read Horstmann, Chapter 11.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
CMSC 202 Inheritance II. Version 10/092 Inherited Constructors? An Employee constructor cannot be used to create HourlyEmployee objects. Why not? We must.
COMP Inheritance Basics Yi Hong June 09, 2015.
Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 11 Inheritance and Polymorphism.
Access Modifiers Control which classes use a feature Only class-level variables may be controlled by access modifiers Modifiers 1. public 2. protected.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Java – Methods Lecture Notes 5. Methods All objects, including software objects, have state and behavior. example, a student as an object has name, address,
Chapter 13 Interfaces and Inner Classes Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Basic Syntax อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 2.
Further Abstraction Techniques Chapter 10. Abstract Classes There are times when you do not want someone to be able to make an object of your class. For.
CMSC 202 Polymorphism 2 nd Lecture. Aug 6, Topics Constructors and polymorphism The clone method Abstract methods Abstract classes.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 7 : Interfaces King Fahd University of Petroleum & Minerals College of Computer.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
More About Java and Java How to Program By Deitel & Deitel.
A Concrete Presentation on Abstract Classes and Methods, Interfaces, and Polymorphism CSC 202.
Polymorphism 2nd Lecture
Inheritance and Polymorphism
EKT 472: Object Oriented Programming
Polymorphism 2nd Lecture
Polymorphism 2nd Lecture
abstract classes and casting objects
UML Class Diagram: class Rectangle
Using local variable without initialization is an error.
Computer Science II Exam 1 Review.
Abstract Classes.
Inheritance 2nd Lecture
Polymorphism 2nd Lecture
null, true, and false are also reserved.
Comp 249 Programming Methodology
Polymorphism CT1513.
Inheritance 2nd Lecture
Inheritance.
Inheritance 2nd Lecture
Abstract methods and classes
مظفر بگ محمدی دانشگاه ایلام
Abstract Classes and Interfaces
Abstract Classes and Interfaces
CMSC 202 Inheritance II.
Chapter 8 Abstract Classes.
Presentation transcript:

Abstract methods and classes

Abstract method A placeholder for a method that will be fully defined in a subclass.

Abstract method An abstract method has a complete method heading with the addition of the keyword abstract. Cannot be private or final. Ex. abstract public double getPay ( ); abstract public void doSomething ( int count );

Abstract class A class that has at least one abstract method is called an abstract class. The class definition must have the keyword abstract. Ex. abstract public class Feet { … abstract void doSomething ( int count ); …}

Abstract vs. concrete class A class without any abstract methods is called a concrete class.

Points to remember You cannot create an instance of an abstract class. –Ex. Employee joe = new Employee(); //the above is illegal if Employee is abstract

Points to remember An abstract class is a type. Therefore you can use abstract classes as parameters to functions. Ex. (perfectly “legal”) public abstract class Employee { … public boolean samePay ( Employee other ) { …}…}

Points to remember An abstract class is a type. Therefore you can use abstract classes as variable types for concrete classes derived from the abstract class. Example follows…

Points to remember Ex. (perfectly “legal”) public abstract class Employee { …} public class HourlyEmployee extends Employee { …} public class SalaryEmployee extends Employee { …}… Employee e = new HourlyEmployee();