0% found this document useful (0 votes)
66 views2 pages

Abstract Class Final Class

Abstract classes and interfaces define behaviors for other classes to inherit while final classes cannot be inherited. Abstract classes can contain both abstract and concrete methods but interfaces can only contain abstract methods. Classes can be instantiated to create objects while interfaces cannot be instantiated and are used to implement multiple inheritance.

Uploaded by

sksankari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views2 pages

Abstract Class Final Class

Abstract classes and interfaces define behaviors for other classes to inherit while final classes cannot be inherited. Abstract classes can contain both abstract and concrete methods but interfaces can only contain abstract methods. Classes can be instantiated to create objects while interfaces cannot be instantiated and are used to implement multiple inheritance.

Uploaded by

sksankari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Abstract class Final class

Declared using the keyword abstract Declared using the keyword final

Methods in an abstract class can be Methods in a final class must be concrete


concrete methods and abstract methods. methods.

Abstract class must be inherited by Final class cannot be inherited by another


another class. class.

Class Interface

A class packs together a group of An interface is basically a kind of class. It


logically related data items and functions contains variables and methods like a
that work on them. The data items are class. But the difference is that the
called fields or instance variables. The variables of an interface are static and
functions are called methods in Java. final And the methods of an interface are
abstract methods by default.

We can instantiate as many objects we We cannot instantiate an object of


want for a class. interface type. We can only create
reference variables.

Example: Example:

class Print interface Common


{ int n; { void display(int a); }
void display(int a) class Print implements Common
{ n = a; { int n;
System.out.println(n); void display(int a)
} { n = a;
public static void main(String a[]) System.out.println(n);
{ Print obj = new Print(); }
obj.display(5); public static void main(String a[])
} { Print obj = new Print();
} Common ref = obj;
ref.display(5);
}
}

Interface Abstract Class

An interface is basically a kind of class. It Abstract class only defines a generalized


contains variables and methods like a form that will be shared by all of its
class. But the difference is that the subclasses, leaving it to each subclass to
variables of an interface are static and fill in the details. It contains instance
final And the methods of an interface are variables, concrete methods and abstract
abstract methods by default. methods.

We cannot instantiate an object of An abstract method cannot be


interface type. They are used to implement instantiated. They are used to implement
multiple inheritance. single and multilevel inheritance.

Final method Abstract method

A super-class method that is declared as Abstract methods are methods for which
final cannot be overridden in the sub no coding is defined; and the subclass can
class. provide its own coding.

Hence, final keyword is used to prevent To declare an abstract method, the general
method overridden. form is –

General form- abstract type method_name(parameter-


list);
final type method_name(parameter list)
Any class that contains one or more
{ // method definition
abstract methods must also be declared
} abstract.

You might also like