affiliate_link

Sunday, June 10, 2012

OOP Q&A

1. What is the difference between Abstract class and Interface?
Abstract Class
An abstract class can have one or more abstract functions but not necessarily all functions have to be abstract.
Abstract function needs to be implemented in its extending class
Abstract classes can have function definitions as well as implementations

Interface
Interfaces can only have abstract functions which must be implemented in extending class

2. What is the difference between encapsulation and abstraction?

Encapsulation
Encapsulation means information hiding i.e hiding all the complexity in one class.
Encapsulation can be achieved by grouping data and behavior in one class that is capsule and making use of access modifiers like public, protected, private along with inheritance, composition or aggregation.

Like Vehicle class has start and stop behaviors which can be inherited by Car class without knowing all the complexities involving in the start & stop functions

Abstraction
Abstraction is the characteristics of an object which differs it from other objects
Abstraction can be achieved by defining a class having one or more abstract methods which is nothing but characteristics which should be implemented by the extending class

No comments: