0% found this document useful (0 votes)
74 views8 pages

Abstract Classes

zxZxZxZxZxZasASasSasASasASDFGBDFBHRGFH' GHFNHGHFHFHF

Uploaded by

John Son
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views8 pages

Abstract Classes

zxZxZxZxZxZasASasSasASasASDFGBDFBHRGFH' GHFNHGHFHFHF

Uploaded by

John Son
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

ABSTRACT CLASSES

WHAT IS AN ABSTRACT METHOD?


There are situations in which you will want to define a superclass that declares the structure of a given abstraction without providing a complete implementation of every method.
Syntax of abstract method

abstract

return-type

methodName(ParameterListrf)

Ex : public abstract void eat();

ABSTRACT EXAMPLE
abstract class AbstractMethods{ public void test ();// Compile error need to use abstract keyword

abstract int test (int a); abstract boolean test ();// can be overloaded abstract Object display(); }

FEATURES OF ABSTRACT METHODS:

[Link] methods need to use abstract keyword [Link] methods can not have a method body [Link] methods should end with a semi colon ;

ABSTRACT CLASS

When a class is having at least one abstract method the class itself must be abstract. But if a class is abstract it does not require to have abstrac methods. Source Code

abstract class AbstractMethods{ abstract int test (int a); public Object display(){} }

ABSTRACT CLASS
Abstract classes cant make objects.
abstract class AbstractMethods{//Compile error public static void main(String args[]){ AbstractMethods a=new AbstractMethods();//Compile error } }

IMPLEMENTING ABSTRACT METHODS


Abstract Methods can be implement to the subclass of the abstract class. When implement the abstract method to the subclass , it will override to the concrete class without the abstract modifier.

abstract class Animal{ public void eat(); public void walk();//Must Implement } class Cat extends Animal{ public void eat(){ [Link](Eating fish and rice) } }

END

You might also like