[go: up one dir, main page]

0% found this document useful (0 votes)
7 views15 pages

Lecture 8.1 - Abstraction

Uploaded by

zarifsyed20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views15 pages

Lecture 8.1 - Abstraction

Uploaded by

zarifsyed20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Abstraction

Course Code: Course Title: Object Oriented Programming -


1(JAVA)

Dept. of Computer Science


Faculty of Science and Technology

Lecturer No: Week No: Semester:


Lecturer: Sifat Rahman Ahona, ahona@aiub.edu
Lecture Outline

1. Abstraction
2. Abstract Class
3. Abstract Method
4. Final Keyword
Abstraction
Definition of Abstraction

• It means ‘Hiding the Details’.


• It is a process where implementation is hidden and its functionality is shown
to user.
Abstraction
Example of Abstraction

Real Life Example:


Abstraction

In programming, this concept of hiding the details is known as abstraction.

We can hide the details of a class or a method.


• Abstract Class
• Abstract Method
Abstract Class

• An abstract class is a class that we can not


instantiate (can not create object).
• However, We can use Object Reference of an
abstract class.
• The keyword abstract is used to denote
abstract class.
• public abstract class MyClass{. . .}
Abstract Class

• An abstract class may have attributes.


• An abstract class may have constructors but we can
not call the constructors using the new keyword.
• However, super( ), super(…), this( ), this(….) can be
used to call constructors of an abstract class.
Abstract Class

• An abstract class may have regular methods.


• An abstract class may have abstract methods.
• It is not necessary that an abstract class must have
an abstract method.
• So, it possible to have both regular methods and
abstract methods in any number combination in a
abstract class.
Abstract Class

• An abstract class MUST have a child class.


• This child class may be a regular class or may be
another abstract class.
• If the child class is another abstract class, that child
class will have another child class which has to be
a regular class.
• So, at least one regular class will inherit the
abstract class/classes in one way or the other.
Abstract Method

• An abstract method is like a regular method but it


does not have anybody.
• An abstract method is denoted with the keyword
abstract.
public abstract void show( );
• As, an abstract method does not have any body, it
does not have the ‘{ }’. Instead, it has a ‘ ; ’ .
Abstract Method

• An abstract method must be inside an


abstract class.
• As, an abstract class must have a child class,
that child class should override/implement
(give body to) all the abstract methods (if
any) of that abstract class.
• If it does not override/implement one/any of
the abstract methods, the child class will have
to be declared as another abstract class.
Example

public abstract class Alpha{ public class MyAlpha extends Alpha{

}
public void show( ){. . . }
public void print( ){. . . } }
public void display( ){. . . }

public abstract class Bravo{ public class MyBravo extends Bravo{

}
public abstract void show( );
public void print( ){. . . }
}
public void display( ){. . . }
public void show( ){. . .}

X
public abstract class Charlie{ public class MyCharlie extends Charlie{
public abstract void show( ); public void display( ){. . .}
public abstract void print( ); public void show( ){. . . }
} }
Example

public abstract class Alpha{ public class MyAlpha extends Alpha{


public void show( ){. . . } public void display( ){. . . }
public void print( ){. . . } }
}

public abstract class Bravo{ public class MyBravo extends Bravo{


public abstract void show( ); public void display( ){. . . }
public void print( ){. . . } public void show( ){. . .}
} }

public abstract class Charlie{ public abstract class MyCharlie extends Charlie{


public abstract void show( ); public void display( ){. . .}
public abstract void print( ); public void show( ){. . . }
} }
Books

1. Java Complete Reference, 7th Edition, By Herbert Schildt.

2. A Programmer's Guide to Java SE 8 Oracle Certified Associate, Khalid A. MughalRolf W.


Rasmussen

3. Java How to Program Java, 9th Edition, By Deitel and Deitel.

4. The Java Language Specification, By J. Gosling, B. Joy, G. Steele, G.Bracha and A.


Buckley

5. Introduction to Programming Using Java, 6th Edition, By David j. Eck

6. Head First Java, By Kathy Sierra and Bert Bates


References

1. 1. Java Complete Reference, 7th Edition, By Herbert Schildt.

2. A Programmer's Guide to Java SE 8 Oracle Certified Associate, Khalid A.


MughalRolf W. Rasmussen

2. The Java Tutorials. http://docs.oracle.com/javase/tutorial/

You might also like