what is Abstraction?

Abstraction means hiding the Implementation and showing only the functionality.

As when user purchase a Car they only see Car look, seat, performance etc. but there we hide how engine are work.

Abstraction is get from Abstract class and interfaces.

Abstract class :-

A class which contain abstract keyword called Abstract class.

An abstract class may contain abstract method or not. If there are abstract method in a class, then that class should be abstract class. Abstract class contain method with body or without body.

				
					abstract class Employee {
	abstract void test();
}

public class EmployeeMain extends Employee {
	public void test() {
		System.out.println("welcome to abstraction");
	}

	public static void main(String[] args) {
		EmployeeMain e = new EmployeeMain();
		e.test();
	}
}
				
			

Interface :-

From interface we can get multiple inheritance.
Inside interface there are only abstract method, no method body.

				
					interface Shape {
	public void draw();
}

public class ShapeMain implements Shape {

	public void draw() {
		// TODO Auto-generated method stub
		System.out.println("shape is a circle");
	}

	public static void main(String[] args) {
		ShapeMain s = new ShapeMain();
		s.draw();
	}
}
				
			

what is Abstraction? Read More »