Sie sind auf Seite 1von 3






Real time entity.
Has state and behavior.
It is an instance of a class.
State - Set of values of an object at any particular time.
Behavior -Implemented as Methods.
Blue print or template for an object.
Logical entity.
Wrapping of data and behavior of and object into a single unit(unit means
classes or interfaces).
It enables data hiding concept.
Data hiding means hiding irrelevant information from the users of a class and
exposing only relevant information.
Example: Consider the example of a linked lists getSize() method. We might
be now using a variable named size that is updated on every insert / delete
operation. Later we might decide to traverse the list and find size every time
someone asks for size. But if some code was directly accessing the size
variable, we would have to change all those code for this change. However if
we were accessing the size variable through a getSize()method, other code can
still call that method and we can do our changes in that method.
Describes the parent child relationship between two classes.
Class can get some of its characteristics from a parent class and then add
more unique features of its own.
Example: Vehicle (Parent/Base/super class) ; Car (Child/derived/subclass).
A subclass does not inherit the private members of its parent class.
Java supports multiple inheritance (multiple parents, single child) only through
Ability to change form.
One task is performed by different ways.
Achieved by method over loading and overriding.
Overloading multiple methods having same name with different signature
based on the number and type of arguments we call that method
Note : Java doesn't allow operator overloading except that "+" is
overloaded for class String
Overriding We can override an instance method of parent class in the child
Method called will depend on the object at runtime, not the
reference type
Is not applicable for static methods or variables
Rules for overriding:
The argument list must be same as that of the overridden
The return type must be the same as, or a subtype of the
return type declared in the parent class method (also called



covariant return type).

In case of primitives, return types should be same; even int
and short, or double and float, will give compilation error
that: "The return type is incompatible with...".
Instance methods can be overridden only if they are
inherited by the subclass.
Private methods are not inherited and hence cannot be
Protected methods can be overridden by a subclass within
the same package.
Final classes cannot be inherited and final methods cannot
be overridden.
The overriding method can throw any new unchecked
(runtime) exception.
The overriding method must not throw checked exceptions
that are new or broader than those declared by the
overridden method.
You cannot make the access modifier more restrictive, but
you can make less restrictive.
Public cannot be made default, but a default can be made
Hiding internal details and showing functionality.
captures only those details about an object that are relevant to the current
Java provides interfaces and abstract classes for describing abstract types.
An interface is a contract or specification without any implementation, can't
have behavior or state.
Abstract class is a class that cannot be instantiated, but has all the properties
of a class including constructors.
Abstract Class :
Marked as abstract
They cannot be instantiated
has all properties of class including constructors
Can have state and can be used to provide skeletal implementation
Can have both abstract and concrete methods
A concrete class should extend an abstract class (using keyword
extends) and implement all abstract methods.
Can use this pointer
Can have private or any access level methods
Can have synchronized methods
Abstract keyword is implicit for interface methods, but can also be declared
Don't have state, behavior or constructors.
They can have static constant variables (public, static and final).
Variables of an interface are implicitly public, static and final.
A concrete class should implement an interface (using keyword implements)
and implement all abstract methods.

An interface can extend another interface using extends keyword.