Difference between abstract classes and interfaces?
Posted by Raj
Abstract Class:
- To define a class as Abstract, the keyword abstract is to be used.
- In abstract class at least one method must be abstract.
- we can create object of abstract class.
- abstract classes may not be instantiated.
- The child classes which inherits the property of abstract base class, must define all the methods declared as abstract.
- Any class that contains at least one abstract method must also be abstract.
- If the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private.
- Abstract class can contain variables and concrete methods.
- A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class.
Interfaces:
- In interface all the method must be abstract.
- All methods declared in an interface must be public.
- Interfaces cannot contain variables and concrete methods except constants.
- A class can implement many interfaces and Multiple interface inheritance is possible.
- To extend from an Interface, keyword implements is used.
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
OOP interview questions and answers,
PHP,
PHP interview questions and answers
.You can leave a response, or trackback from your own site.