0

I am Studying PHP and i was thinking,

Methods inside Abstract Class or Interface is called abstract methods.

My Question:

Are Abstract methods defined inside Abstract Class/Interface is Not included inside the subclass?

If it's true it means that:

What only inside the subclass is the methods/properties not defined as abstract, what means that interfaces cant creat subclass when being implement.

Also means:

That when abstract method defined from abstract class/interface the class that extends/imploment the abstract class/interface is only take a look at the methods signatures and ensure that those methods was being overriding(witch not really overiding, rewrite is a better word to say(Although i hear overriding)).

If can some one please help me understand professionally the abstract methods, have a nice Day.

2
  • I'm having trouble understanding the question ... are you asking whether abstract methods can be defined inside subclasses? Commented Jun 1, 2012 at 8:50
  • This is one of my questions, Thank everyone i am read the answers now. Commented Jun 1, 2012 at 9:16

2 Answers 2

4

An abstract class is simply a class that contains one or more abstract methods. An abstract class can not be instantiated because it is basically incomplete. It serves as a kind of blueprint for its subclasses.

An abstract method is one that is not fully defined. It has a signature but no implementation. The implementation must be done in the subclass. A subclass automatically inherits any non-abstract methods but the abstract ones must be implemented.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you i got it now, Have a nice day.
1

In ptractice this is what happens:

An interface can inherit from one or more interfaces, and the class that implements the interface implements all the base interfaces too. You cannot have instances of an interface, instead you need to have a class that implements the interface and have objects of that class. If something requires an object which type is one of those interfaces, then an object of the mentioned class will fit.

An abstract class can inherit from one and no more than one class. You cannot create intances of the abstract class, instead you need in created a derived class that inherits from it, and have objects of that one. It can also contain fileds, and abstract or not abstract methods, and implement one or more interfaces. The class that inherits from the abstract class must be abstract or implement all the abstract method inherited from the base class (if the class is abstract then those abstract methods are inherited to be implemented in any futher derived class). If something requires an object which type is one of the interfaces implemented on the abstract base class or of the abstract base class itself, then an object of the mentioned derived class will fit.


When the concept of interface was introduced, multiple inheritance of classes was more common, and a interface was just a kind of class (some still refers to it like that). As time passes interface has became a separate concept and multiple inheritance has been constrained to only be allowed between interfaces.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.