Tuesday 3 March 2015

Data Abstraction in Java

        Data abstraction is the process of hiding the implementation details and showing only the functionality. In java you can declare the structure of abstract class in parent class and the actual implementation will be defined in their child classes.

Eg: The calculation of area will be the functionality and depending on either it is triangle ,rectangle or square your implementation details will be different.

Abstract class: 
      A class which is declared with abstract keyword will be the abstract class in java. If a class is abstract then you cannot create an instance for that class. You have to inherit the abstract class and need to create the instance for the child class.

Syntax:
abstract class class_name{}

Abstract Method: 
      If a method is created with the abstract keyword and the method does not have any implementation logic in the method body is called abstract method.
If a class has at least one abstract method then the class should be abstract class.

Syntax:
abstract return_type method_name();

Example:
TO copy the code select+ctrl+C


Output:








No comments: