PHP OOPs Part4

31. What is the difference between new and override?
The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function.

32. What are the various types of constructors?
There are three various types of constructors , and they are as follows:.
- Default Constructor – With no parameters.
- Parametric Constructor – With Parameters. Create a new instance of a class and also passing arguments simultaneously.
- Copy Constructor – Which creates a new object as a copy of an existing object.

33. What is early and late binding?
Early binding refers to assignment of values to variables during design time whereas late binding refers to assignment of values to variables during run time.

34. What is ‘this’ pointer?
THIS pointer refers to the current object of a class. THIS keyword is used as a pointer which differentiates between the current object with the global object. Basically, it refers to the current object.

35. What is the difference between structure and a class?
Structure default access type is public , but class access type is private. A structure is used for grouping data whereas class can be used for grouping data and methods.
Structures are exclusively used for dataand it doesn’t require strict validation , but classes are used to encapsulates and inherit data which requires strict validation.

36. What is the default access modifier in a class?
The default access modifier of a class is Private by default.

37. What is pure virtual function?
A pure virtual function is a function which can be overridden in the derived classbut cannot be defined. A virtual function can be declared as Pure by using the operator =0.
Example -.
Virtual void function1() // Virtual, Not pure
Virtual void function2() = 0 //Pure virtual

38. What are all the operators that cannot be overloaded?
Following are the operators that cannot be overloaded -.
Scope Resolution (:: )
Member Selection (.)
Member selection through a pointer to function (.*)

39. What is dynamic or run time polymorphism?
Dynamic or Run time polymorphism is also known as method overriding in which call to an overridden function is resolved during run time, not at the compile time. It means having two or more methods with the same name,same signature but with different implementation.

40. Do we require parameter for constructors?
No, we do not require parameter for constructors.