Step 15:Oops- 3rd Concept: Abstraction: 10th hour + code

Definition-

Abstraction is a concept of showing only functionality and hiding procedure.

In java, only name of method is given and not the body.

-Abtraction can be applied on classes and methods using abstract keyword.

– In abstraction we focus on “what” the object does instead of “how”.

1- abstract class

– Only abstract class can have abstract methods

-Abstract class can have normal methods too.
-Object of abstract class can’t be created directly
– abstract classes should be inherited to be useful

main-qimg-398f9e7c5c323aab32488ff8310a777c

[Think of an abstract class as an almost complete car by your dad who left over the choice of engine to be provided by you.]

2- abstract method

– abstract method can’t have method body
– abstract methods should be overridden to be useful.

code samples are here

1- Abstraction

package abstraction14;

abstract class A{

abstract void shw();
abstract void disp();
}

public class ExampleAbstraction extends A {

@Override
void shw() {
System.out.println("hi");
}

@Override
void disp() {
System.out.println("bye");
}
public static void main(String[] args) {

ExampleAbstraction e1=new ExampleAbstraction();
e1.shw();
e1.disp();
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.