Home Java Overview Maven Tutorials

Sunday, 15 January 2017

Abstraction in Java with example

Abstraction in Java with example

For Video : CLICK HERE

If a class contain any abstract method then the class is declared as abstract class.
An abstract class is never instantiated. It is used to provide abstraction, although it does not provide 100% abstraction because it can also have concrete method.
Java Abstract classes are used to declare common characteristics of subclasses, It can only be used as a superclass for other classes that extend the abstract class.

Abstraction Example :

abstract class Chandan
int z =10;
abstract public int sum(int x, int y);
abstract public int sub(int x, int y);
public class Abstract extends Chandan
public int sum(int x, int y)
public int sub(int x, int y)
public static void main(String args[])
int x = 20;
int z = 30;
Abstract obj = new Abstract();
System.out.println("your sum is :" +obj.sum(4,7));
System.out.println("your subtraction is :" +obj.sub(4,7));
Output :
your sum is :11
your subtraction is :-3

Tags:Abstraction in java with exampleWhat is abstraction in java

1 comment:

  1. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.

    software testing course in chennai