Publish your story - poem - jokes free online--click here

JAVA

Abstract Class in Java

Abstract class
Abstract class is an incomplete class because at least one method in abstract class must be abstract (without definition). Hence we can’t make the object of the abstract class and can’t create any constructor of abstract class.

Difference between Abstract class and Interface
Abstract class
11.       It has at least one method abstract so other function can be defined in class.
22.       It is extended not implemented
33.       Only abstract method is needs to overriding in sub class. Other method can be called with object of derived class.
44.       “abstract” keyword is used before the class or method name to make it abstract

Interface
1.       None of method of interface is defined in base class
2.       It is implemented not extended
3.       All method of base class must be overrided in all derived class
4.       “interface “ keyword is used before the name of class to make it interface.

Example of abstract class and method

import java.util.*;
abstract class base
{
                abstract public void show();
                void disp()
                {
                                System.out.println("this function is defined is abstract class");
                }
}
class derived extends base
{
                public void show()
                {
                                System.out.println("this is overidded function of base class");
                }
}
public class abc
{
                public static void main(String as[])
                {
                                                derived d=new derived();
                                                d.show();
                                                d.disp();
                }

}

No comments:

Post a Comment