BCA Abstraction
BCA Abstraction
Abstraction in Java
• For example, sending SMS where you type the text and send the message.
You don't know the internal processing about the message delivery.
Ways to achieve Abstraction
• There are two ways to achieve abstraction in java.
1. Abstract class (0 to 100%)
2. Interface (100%)
1. Abstract class in Java
}
Abstract Method in Java
Example:
Example
interface A
{
void print();
}
class B implements A
{
public void print()
{
System.out.println("Hello");
}
public static void main(String a[])
{
B b1 = new B();
b1.print();
}
}
Cont…
Output:
Hello
Multiple inheritance with the help of
Interface
interface X
{
void display();
}
interface Y
{
void display();
}
class C implements X, Y
{
public void display()
{
System.out.println("Hello");
}
public static void main(String x[])
{
C c1 = new C();
c1.display();
}
}
Output:
Hello