PHP Quizs Question & Answers Basics of Oriented-1

Q 1. Which one of the following property scopes is not supported by PHP?
A. friendly
B. final
C. public
D. static

Show Answer Answer:-A. friendly
Explanation PHP supports five class property scopes: public, private, protected, final and static.

Q 2. Which one of the following can be used to instantiate an object in PHP assuming class name to be Foo?
A. $obj = new $foo;
B. $obj = new foo;
C. $obj = new foo ();
D. obj = new foo ();

Show Answer Answer:-C. $obj = new foo ();
Explanation To create a new object in PHP we can use the new statement to instantiate a class.

Q 3. The practice of separating the user from the true inner workings of an application through well-known interfaces is known as _________
A. Polymorphism
B. Inheritance
C. Encapsulation
D. Abstraction

Show Answer Answer:-C. Encapsulation
Explanation In object-oriented PHP encapsulation is a concept of wrapping up or binding up the data members and methods in a single module.

Q 4. Which of the following term originates from the Greek language that means “having multiple forms,” defines OOP’s ability to redefine, a class’s characteristics?
A. Abstraction
B. Polymorphism
C. Inheritance
D. Differential

Show Answer Answer:-B. Polymorphism
Explanation The word polymorphism is derived from Greek word poly which means “many” and morphism which means the property which helps us to assign more than one property.

Q 5. The practice of creating objects based on predefined classes is often referred to as ______________
A. class creation
B. object creation
C. object instantiation
D. class instantiation

Show Answer Answer:-D. class instantiation
Explanation In object-oriented programming, classes are the blueprints of php objects. Classes do not actually become objects until instantiation is done. When someone instantiates a class, it creates an instance of it, thus creating the object. In other words, instantiation is the process of creating an instance of an object in memory.

Q 6. Which one of the following is the right way to define a constant?
A. constant PI = “3.1415”;
B. const $PI = “3.1415”;
C. constant PI = ‘3.1415’;
D. const PI = ‘3.1415’;

Show Answer Answer:-D. const PI = ‘3.1415’;
Explanation Class constants are created like: const NAME = ‘VALUE’;

Q 7. Which one of the following is the right way to call a class constant, given that the class is mathFunction?
A. echo PI;
B. echo mathFunction->PI;
C. echo mathFunction::PI;
D. echo mathFunction=PI;

Show Answer Answer:-C. echo mathFunction::PI;
Explanation The Scope Resolution Operator “::” is a token that allows access to static, constant, and overridden properties or methods of a class.

Q 8. Which one of the following is the right way to invoke a method?
A. $object->methodName();
B. object->methodName();
C. object::methodName();
D. $object::methodName();

Show Answer Answer:-A. $object->methodName();
Explanation “->” is a dynamic class method invocation in PHP.

Q 9. Which of the following is/are the right way to declare a method?

i) function functionName() { function body }
ii) scope function functionName() { function body }
iii) method methodName() { method body }
iv) scope method methodName() { method body }

A. Only ii)
B. Only iv)
C. i) and ii)
D. iii) and iv)

Show Answer Answer:-C. i) and ii)
Explanation In case of public methods, you can forgo explicitly declaring the scope and just declare the method like you would a function.

Q 10. Which of the following method scopes is/are not supported by PHP?

i) private
ii) friendly
iii) static
iv) abstract

A. Only iv)
B. Only ii)
C. ii) and iv)
D. Only i)

Show Answer Answer:-B. Only ii)
Explanation PHP supports six method scopes: public, private, final, static, protected and abstract. But it does not support friendly.

Comments

Leave a Reply

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

You cannot copy content of this page