You are on page 1of 2

Default Classes :

1. If a class is declared as the default, we r allowed to access that class from


within
the package only, if we r trying to access from outside package, it results in
CTE.
2. Default access is also known as Package Level Access
3. There is no default keyword for class level modifiers. But default keyword is
there for switch statement.
Abstract Classes :
1. Would be used for good programming practice. Most used by real-time experts.
2. abstract is a keyword which can be applied for classes and methods. i.e we
can t apply abstract keyword for variables.
3. If we don t know about implementation of a method, still we r allowed to
declare such type of methods in our classes by using abstract modifier.
4. if a method is declared as abstract in a class, it indicates that we don t know
about implementation, child class is responsible for providing implementation.
The following is the valid abstract method declaration
abstract int no of wheels ( );
84
Note : ( ; ) is mandatory and it indicates no implementation is defined here.
But, abstract int no of wheels ( ){ }; results in CTE.
Because { } indicates implementation which is not allowed for an abstract
method.
5. abstract is the term which never talks about implementation. Hence it is illega
l
to combine abstract keyword with any of the modifier which talks about
implementation. So, the following combinations r illegal, in case of methods.
final
syncharized
abstract native
private
static
strictfp
The valid combination r : abstract public, protected.
Concrete methods : Methods having body.
6. If a class declared as abstract, then we r not allowed to create an instance
of that
class. If the class contains, at least one abstract method, it indicates that th
e
implementation is not complete. Then we r not allowed to create an instance of
that class. Hence it must be declared as abstract . Class containing atleast
one abstract method must be declared as abstract, violation leads to CTE.
Eg : abstract
class vehicle
{
abstract int no of wheels ( );
}
7. It is not mandatory that abstract classes should at least contain single abst
ract
method i.e abstract classes have a possibility of having zero (0) abstract
method.
Eg : HhpServlet class is an abstract class which doesn t contain a single
abstract method.
What is d use of creating HhpServlet as abstract class ?
8. If u don t want to create an instance of the class, declare that class as abstr
act
class; whether it contains abstract methods or not.
85
9. Inside abstract classes we r allowed to keep constructors, i.e an abstract cl
ass

may contain constructors but the programmer is not allowed to create an object
of abstract class, but internally JVM is allowed to create an instance.
10. The 1st child class extending an abstract class is responsible to provide
implementation for all the abstract methods present in the parent class,
otherwise the child class should also be declared as abstract .
Final Classes :
1. final is a keyword which can be applied for the classes methods and variables.
2. final methods :
If a method declared as final, we r not allowed to over side this method in the
child class violation leads to CTE.
Eg : Public class A
{
final public void M1( )
{
SOP ( A s M1 Method );
}
}
Class B extends A
{
Public void M1( )
{
SOP ( B s M1 Method );
}
}
CTE : M1( ) in B can t override M1( ) in A.;
Overridden Method is final

You might also like