Home » Php » Advance Php Interview Question » Difference between abstract class and Final class in php

Difference between abstract class and Final class in php

Difference between abstract class and Final class in php

Abstract class : An abstract class is a class which can’t be instantiated and contains one or more abstract methods( methods that are only declared, but their implementation is left for subclasses or we can say Should be a sub-classed to override the functionality of abstract methods).If you use abstract method in a class that means the class is abstract also so you have to declare that class as abstract.An abstract class always needs to be extended in order to be used.

Feature of Abstract class: Abstract class should have a subclass, and method of the abstract class can be altered in sub-classed(Method Overriding).Abstract class can be inherited,it may be contain abstract method but not mandatory, method of this class is partially implemented(some are implemented in this class but someone only declare not implemented, implemented in subclass).

Final Class :A Class which Can’t be inherited by other class, or we can say you don’t able to add new functionality
in this class and never be extends this class .that is called final class.

Feature of Final class :Final class can not contain abstract method because we don’t have subclass of final class.so all method of final class should have implemented.

Static Properties/Variables in PHP

Static Class : Static class is that whose methods and variables can be called without creating the instance of the class.we can not create the instance of static class. Static means which is initialized once.Static properties of class is a property which is directly accessible from class with the help of ::(scope resolution operator). You can declare static property using static keyword. In other word you can make any property static by using static keyword.

class :Static Properties/Variables in PHP : Static properties(Variables and method) of class is a property which is directly accessible from class with the help of ::(scope resolution operator). You can declare static property to append the static keyword before the name of property declaration. or We can say that you can make any property static by using static keyword.

Basic example of static variable in php class :

Basic example of static Method in php class :

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">