JAVA

ABSTRACTION AND INTERFACE IN JAVA

0  0 2015-09-24 10:36:47

Abstraction is a process of hiding implementation details and showing only the functionality to the user. It mainly focuses on what the object does not on how it does.

There are two ways to achieve abstraction such as Abstract Class and Interface.

Abstract class is a class which is declared with abstract keyword and cannot be instantiated. Abstract class needs to be extended compulsory and its methods should be implemented.

Interface is a mechanism used to achieve full abstraction and we can have only abstract methods in it.

Abstract class doesn't support multiple inheritance whereas interface does support. We can have final, non-final, static and non-static variables in Abstract class whereas Interface has only static and final variables.

Example of Abstract class and Interface:

public interface WebTechnology

{

void Design();

void Development();

}

abstract class Tech implements WebTechnology

{

            public void Hosting()

            {System.out.println("This is a block of hosting");}

}

Class Test extends Tech

{

            public void Design()

            {System.out.println("This is a block of Design");}

            public void Development()

            {System.out.println("This is a block of Development");}

}

class Test24{

            public static void main(String args[])

            {

                        WebTechnology WT= new Test();

                        WT.Design();

                        WT.Development();

                        WT.Hosting();

            }

}

Comments (0)

Post Your Comments

Headquarter



Hong Kong Office



Find Us On

Ziuby
Ziuby