Introduction to Object Oriented Programming in PHP | Adv PHP | Multiple Choice Questions With Answer

 






UNIT-1-OOP

 


 

 

Q.1)--------is about writing procedures or functions that perform operations on the data. 

Sol  

A)procedural programming 

B) function programming 

C)object oriented programming 

D)class  

 

Ans :A 

 

Q.2)while--------is about creating objects that contain both data and functions. 

Sol 

 

A)procedural programming 

B) function programming 

C)object oriented programming 

D)method 

Ans :C 

 

Q.3)A class is defined by using the---keyword, followed by the name of the class and a pair of curly braces ({}). All its properties and methods go inside the braces 

Sol 

A)procedural programming 

B) function programming 

C)object oriented programming 

D)class  

 Ans :D 

Q.4)----are nothing without objects! We can create multiple objects from a class  Sol 

 

A)procedural programming 

B) function programming 

C)object oriented programming 

D)class  

 

Ans :D 

 

 

 

Q.5)Each----has all the properties and methods defined in the class, but they will have different property values. 

Sol 

A) object  

B)  $this 

C)instanceof 

 D)class  

Ans :A 

 

Q.6)-----of a class is created using the new keyword 

Sol 

A) object  

B)  $this 

C)instanceof 

 D)class  

 

Ans :A 

 

  

Q.7)The-----keyword refers to the current object, and is only available inside methods  Sol 

 

A) object  

B)  $this 

C)instanceof 

 D)class  

 

Ans :B 

  

Q.8)Objects of a class is created using the-----keyword 

Sol 

 

A) new  

B)  $this 

C)instanceof 

 D)class  

 

Ans :A 

 

   

Q.9)we change the value of the $name property? There are two ways Inside the-----  &Outside the class 

Sol 

 

A) object  

B)$this 

C)instanceof 

 D)class  

 

Ans :D 

 

Q.10)You can use the----keyword to check if an object belongs to a specific class  Sol 

 

A) object  

B)  $this 

C)instanceof 

 D)class  

 

Ans :C 

 

 

 

Q.11)A-----allows you to initialize an object's properties upon creation of the object  Sol 

 

A) constructor  

B)  in 

C)instanceof 

 D)class  

 

Ans :A 

 

Q.12)If you create a-----function, PHP will automatically call this function when you create an object from a class. 

Sol 

A) __Construct()  

B)___Destruct() 

C)oop 

 D)class  

 

Ans :A 

Q.13)that the construct function starts with two underscores------- 

Sol 

 

A) __ ()  

B)___ () 

C)oop 

 D)class  

 

Ans :A 

 

Q.14)A------ is called when the object is destructed or the script is stopped or exited. 

Sol 

 

A) constructor  

B)destructor 

C)oop 

 D)class  

 

Ans :B 

 

Q.15)If you create a-----function, PHP will automatically call this function at the end   of the script 

Sol 

 

A) __Construct()  

B)___Destruct() 

C)oop 

 D)class  

 

Ans :B 

  

Q.16)Notice that the destruct function starts with------- 

Sol 

 

A) __Construct()  

B)___() 

C)oop 

 D)class  

Ans :B 

 

 

Q.17)-----function that is automatically called when you create an object from a class, and a -------function that is automatically called at the end of the script 

Sol 

A) __Construct() & __destruct() 

B)___Destruct()& input() 

C)oop& procedure 

 D)class  & object 

  Ans :A 

 

Q.18)------stands for Object-Oriented Programming.   

Sol 

 

A) __Construct()  

B)___Destruct() 

C)OOP 

 D)class  

 

Ans :C 

 

Q.19)-----and methods can have access modifiers which control where they can be accessed 

Sol 

 

A)Properties   

B)Destruct 

C)OOP 

 D)class  

 

Ans :A 

 

Q.20)-----the property or method can be accessed from everywhere. This is default 

Sol 

 

A) Properties   

B)public 

C)protected  

 D)private 

Ans :B 

  

 

Q.21)------the property or method can be accessed within the class and by classes derived from that class 

Sol 

 

A) Properties   

B)public 

C)protected  

 D)private 

 

Ans :C 

Q.22)------the property or method can ONLY be accessed within the class 

Sol 

 

A) Properties   

B)public 

C)protected  

 D)private 

 

Ans :D 

 

Q.23)--------in OOP  When a class derives from another class. 

Sol 

 

A) inheritance 

B)public 

C)protected  

 D)private 

 

Ans :A 

 

Q.24)The-----will inherit all the public and protected properties and methods from the parent class. In addition, it can have its own properties and methods. 

Sol 

 

A) inheritance 

B)child class 

C)protected  

 D)private  

Ans :B 

Q.25)An inherited class is defined by using the------keyword 

Sol 

A) inheritance 

B)public 

C)extends 

 D)private 

 

Ans :C 

 

Q.26)---methods can be overridden by redefining the methods (use the same name) in the child class. 

Sol 

 

A) inheritance 

B)public 

C)protected  

 D)private 

 

Ans :A

Q.27)The----keyword can be used to prevent class inheritance or to prevent method overriding 

Sol 

 

A) final 

B)constants 

C)const  

 D)case-sensitive 

 

Ans :A 

 

Q.28)------cannot be changed once it is declared. 

Sol 

 

A) final 

B)constants 

C)const  

 D)case-sensitive 

 

Ans :B 

 

Q.29)Class constants can be useful if you need to define some-------data within a class  Sol 

 

A) final 

B)constants 

C)const  

 D)case-sensitive 

 

Ans :B 

 

Q.30)A class constant is declared inside a class with the-----keyword. 

Sol 

 

A) final 

B)constants 

C)const  

 D)case-sensitive 

 

Ans :C 

 

Q.31)Class constants are--------However, it is recommended to name the constants in all uppercase letters. 

Sol 

 

A) final 

B)constants 

C)const  

 D)case-sensitive 

Ans :D 

 

Q.32)We can access a-------from outside the class by using the class name followed by the scope resolution operator () followed by the constant name 

Sol 

 

A) final 

B)constant 

C)const  

 D)case-sensitive 

  Ans :B

Q.33)-------classes and methods are when the parent class has a named method, but need its child class(es) to fill out the tasks 

Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

Ans :A 

 

Q.34)An------class is a class that contains at least one abstract method  Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :A 

  

Q.35)An------method is a method that is declared, but not implemented in the code. 

Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

Ans :A 

 

Q.36)An abstract class or method is defined with the------keyword 

Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :A 

  

Q.37)When inheriting from an------class, the child class method must be defined with the same name 

Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :A 

 

Q.38)if the-----method is defined as protected, the child class method must be defined as either protected or public, but not private  Sol 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :A 

Q.39)The----class method must be defined with the same name and it re declares the parent abstract method 

Sol 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :B 

 

Q.40)The-----class method must be defined with the same or a less restricted access modifier 

Sol 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :B 

 

 

Q.41)The number of required arguments must be the same. However, the-----class may have optional arguments in addition 

Sol 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :B 

Q.42)-----make it easy to use a variety of different classes in the same way. When one or more classes use the same interface, it is referred to as "polymorphism" 

Sol 

A)abstract  

B)child 

C)interface 

 D)implement 

  Ans :C 

Q.43)Interfaces are declared with the------keyword. 

Sol 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :C 

 

Q.44)------cannot have properties, while abstract classes can 

Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :C 

 

Q.45)All------methods must be public, while abstract class methods is public or protected 

 

Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :C 

Q.46)All methods in an-----are abstract, so they cannot be implemented in code and the abstract keyword is not necessary 

Sol  

A)abstract  

B)cild 

C)interface 

 D)implement 

 

Ans :A 

Q.47)-------keyword is used  in interface 

Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

Ans :D 

 

 

Q.48)To implement an interface, a class must use the-------keyword. 

Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :D 

 

Q.49)A class that implements an interface must------all of the interface's methods. 

Sol 

 

A)abstract  

B)child 

C)interface 

 D)implement 

 

Ans :D 

 

Q.50)PHP only supports---------a child class can inherit only from one single  

Sol  parent. 

A)abstract  

B)child 

C)interface 

 D)single inheritance  

 

Ans :D 

 

 

Q.51)class needs to inherit multiple behaviors? OOP------is used to solve this problem. 

Sol 

 

A)static  

B)self 

C)traits 

D)single inheritance  

 

Ans :C 

 

Q.52)------are used to declare methods that can be used in multiple classes. Traits can have methods and abstract methods that can be used in multiple classes.  Sol  

A)static  

B)self 

C)traits 

 D)single inheritance  

 

Ans :C 

Q.53)Traits are declared with the----keyword 

Sol 

 

A)static  

B)self 

C)traits 

 D)single inheritance  

 

Ans :C 

 

Q.54)------methods can be called directly - without creating an instance of the class first. 

Sol 

 

A)static  

B)self 

C)traits 

 D)single inheritance  

 

Ans :A 

 

Q.55)Static methods are declared with the------keyword 

Sol 

 

A)static  

B)self 

C)traits 

 D)single inheritance  

 

Ans :A 

 

Q.56)A class can have both static and non-static methods. A static method can be accessed from a method in the same class using the-----keyword and double colon (::) 

Sol  

A)static  

B)self 

C)traits 

D)single inheritance    

Ans :B 

Q.57)------properties can be called directly - without creating an instance of a class. 

Sol 

 

A)static  

B)self 

C)traits 

 D)single inheritance  

 

Ans :A 

 

Q.58)An iterable is any value which can be looped through with a-----loop. 

Sol 

 

A)foeach()  

B)self 

C)traits 

 D)single inheritance  

 

Ans :A 

 

Q.59)The-----pseudo-type was introduced in PHP 7.1, and it can be used as a data type for function arguments and function return values. 

Sol   

A)foeach()  

B)self 

C)iterable 

D)single inheritance  

 

Ans :C 

 

Q.60)The-----keyword can be used as a data type of a function argument or as the return type of a function 

Sol   

A)foeach()  

B)self 

C)iterable 

D)single inheritance  

Ans :C  




Post a Comment

0 Comments