Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

Abstraction and Interface in Java

Author: Info Campus
by Info Campus
Posted: Apr 03, 2017

Abstraction:

Abstraction is a process where you show only "relevant" data and "hide" unnecessary details of an object from the user.

Consider your mobile phone, you just need to know what buttons are to be pressed to send a message or make a call, What happens when you press a button, how your messages are sent, how your calls are connected is all abstracted away from the user.

Abstraction is the process where you "throw-away" unnecessary details from an entity you plan to capture/represent in your design and keep only the properties of the entity that are relevant to your domain.

Java course in bangalore

For getting a abstraction we need to use a keyword abstract.abstract keyword use with class. Which indicate that class is incomplete. Abstract class contains abstract methods(incomplete methods) and complete methods.

In below given example we can see that Vehicle is the abstract class.it has complete and abstract methods. These methods are implemented by the class car and Auto.

Exm :

abstract class Vehicle

{

    public abstract int getNoOf

    }

    class Car extends Vehicle

    {

    public int getNoOfWheels()

    {

    System.out.println("No of wheels in Car is 4");

    }

    }

    class Auto extends Vehicle

    {

    public int getNoOfWheels()

    {

    System.out.println("No of wheels in Auto is 3")

    }

    }

    java training center bangalore

Focuses to Remember about Java Abstraction:

  1. Abstraction is the process of selecting important data sets for an Object in your software, and leaving out the insignificant ones.
  2. Once you have modeled your object using Abstraction, the same set of data could be used in different applications.

Interface :

An interface in java is an outline of a class. It has static constants and abstract methods only.

The interface in java is a way to get the complete abstraction. An interface contains all incomplete (Abstract Methods) that a class executes.

Interface contains the methods which are by default public and abstract. These all methods are implemented by the other class.because of that it guarantees for 100% abstraction.

Best core java training in bangalore Through the interface we will be able to get the multiple inheritance.We can’t get the multiple inheritance using class.

Example

interface Printable

{

public abstract void print(); } interface Showable { void print(); } class testinterface1 implements Printable,Showable { testinterface1 obj = new testinterface1(); obj.print(); public void print() { System.out.println("Print the text"); } public static void main(String args[]) { testinterface1 obj = new testinterface1(); obj.print(); } }

Utilisation of Abstraction :

Abstract class is one of the capable builds of Object Oriented Programming and serves to implements Dynamic Polymorphism.

Utilisation of Interface :

1. If you only implement methods in subclasses, the callers will not be able to call them via the interface (not common point where they are defined).

Advance java training in bangalore

  1. Java 8 will introduce default implementation of methods inside the interface, but that should be used as exception rather than rule. All evolution of Stream API was possible due to this change.
  2. Interface guarantees for the 100% abstraction.We can achieve the multiple inheritance.

Author :

Infocampus provides Java course in bangalore with the 100% job support.

4 days free demo classes are available for java training.

Attend Advance Java Training in lesser fees and pay fees in installments.

To get the deep knowledge on Java join java/j2ee classes.

Learn Core & Advance Java in the easy way in Infocampus Software Training Institute.

Contact us at : 9738001024 and for more details on best core java training in bangalore visit at :http://www.infocampus.co.in/java-training-bangalore.html

About the Author

A Real Time Software Training Institute 100% Guaranteed JOB Support Get Real Time Training from Industry Experts Book Free Demo Class

Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Comment 
Pictures
Author: Info Campus

Info Campus

Member since: Feb 08, 2017
Published articles: 45

Related Articles