Object oriented programming concepts in PHP

Is it always necessary to create objects from class?

No. An object is necessary to be created if the base class has non-static methods. But if the class has static methods, then objects don’t need to be created. You can call the class method directly in this case, using the class name.


How much memory does a class occupy?

Classes do not consume any memory. They are just a blueprint based on which objects are created. Now when objects are created, they actually initialize the class members and methods and therefore consume memory.


Can you create an instance of an abstract class?

No. Instances of an abstract class cannot be created because it does not have a complete implementation. However, instances of subclass inheriting the abstract class can be created.


What is a final variable?

A variable whose value does not change. It always refers to the same object by the property of non-transversity.


What are the differences between error and exception?

Exception - Exception can be recovered by using the try-catch block.It occurs at compile time or run time.

Error -An error cannot be recovered.It occurs at run time.


Is it possible for a class to inherit the constructor of its base class?

No, a class cannot inherit the constructor of its base class.


Is it possible to overload a constructor?

Yes, the constructors can be overloaded by changing the number of arguments accepted by the constructor or by changing the data type of the parameters.


What happens when we declare constructor as private?

A private constructor in Java is used in restricting object creation. It is a special instance constructor used in static member-only classes. If a constructor is declared as private, then its objects are only accessible from within the declared class. You cannot access its objects from outside the constructor class.

Comments

Popular posts from this blog

Basic Terminology

What are the main differences between INNODB and MYISAM?

What is normalization in DBMS?