PHP Set 4 (30 mcqs)

1. Which one of the following is not a valid class name?
a) ShopProduct
b) Shopproduct
c) Shopproduct1
d) 1shopproduct
.
2. Fill in the blank with the best option. An Object is a/an ___ of a class.
a) type
b) prototype
c) instance
d) object

3. There are two objects-
$product1 = new Shop();
$product2 = new Shop();
Which one of the following statements is right about them?
a) $product1 and $product2 are same objects of the same type generated from a single class.
b) $product1 and $product2 are different objects of the same type generated from a single class.
c) $product1 and $product2 are same objects of the different type generated from a single class.
d) $product1 and $product2 are different objects of the different type generated from a single class.

4. Which version of PHP introduced the visibility keywords i.e public, private, and protected?
a) PHP 4
b) PHP 5
c) PHP 5.1
d) PHP 5.3

5. Which characters is used to access property variables on an object-by-object basis?
a) ::
b) =
c) ->
d) .

6. Code that uses a class, function, or method is often described as the..
a) client code
b) user code
c) object code
d) class code
.
7. Which keyword precedes a method name?
a) method
b) function
c) public
d) protected

a method name, followed by an optional list of argument variables in parentheses.
8. If you omit the visibility keyword in your method declaration, by default the method will be declared as..
a) public
b) private
c) protected
d) friendly

9. Which function is used to determine whether the variable’s value is either TRUE or FALSE?
a) boolean()
b) is_boolean()
c) bool()
d) is_bool()

10. What will be the output of the following PHP code?
1.<?php
2.    class ShopProductWriter
3.    {
4.        public function write( $shopProduct )
5.        {
6.            $str = “{$shopProduct->title}: ” .$shopProduct->getProducer() .” ({$shopProduct->price})\n”;
7.            print $str;
8.        }
9.    }
10.    $product1 = new ShopProduct( “My Antonia”, “Willa”, “Cather”, 5.99 );
11.    $writer = new ShopProductWriter();
12.    $writer->write( $product1 );
13.?>
a) Error
b) Cather: Willa My Antonia (5.99)
c) Willa: Cather My Antonia (5.99)
d) My Antonia: Willa Cather (5.99)

11. Object-oriented code tries to minimize dependencies by moving responsibility for handling tasks away from ___ and toward the objects in the system.
a) server code
b) client code
c) machine code
d) procedural code

12. Placing a static method for generating ___ objects in the ___ class is convenient.
b) parent child
c) final static
d) static final

13. The extent to which proximate procedures are related to one another is known as…
a) Coupling
b) Balancing
c) Cohesion
d) Co-relation

14. ___ occurs when discrete parts of a system’s code are tightly bound up with one another so that a change in one part necessitates changes in the others.
a) Loose Coupling
b) Tight Coupling
c) Co-relation
d) Balancing

15. ___ code makes change easier because the impact of altering an implementation will be localized to the component being altered.
a) Orthogonal
b) Cohesion
c) Coupling
d) Balancing

16. Polymorphism is also know as…
a) switch
b) overact
c) encapsulation
d) class switching

17. Which one of the following is know as the key to object-oriented programming ?
a) Polymorphism
b) Encapsulation
c) Data Abstraction
d) Orthogonality

18. Which one among the following means tight coupling ?
a) Code Duplication
b) Inheritance
c) Encapsulation
d) Polymorphism

19. UML stands for?
a) unified mailing language
b) unified modeling logo
c) undefined modeling language
d) unified modeling language
.
20. In a class diagram the class is divided into three sections, what is displayed in the first section?
a) Class Attributes
b) Class Declaration
c) Class Name
d) Class Functions

21. What will be the output of the following PHP code ?
1.<?php
2.one = 1;
3.two = 2;
4.three = 3;
5.four = 4;
6.echo “one / two + three / four”;
7.?>
a) 0.75
b) 0.05
c) 1.25
d) Error

22. What will be the output of the following PHP code ?
1.<?php
2.$on$e = 1;
3.$tw$o = 2;
4.$thre$e = 3;
5.$fou$r = 4;
6.echo “$on$e / $tw$o + $thre$e / $fou$r”;
7.?>
a) 0.75
b) 0.05
c) 1.25
d) Error

23. What will be the output of the following PHP code ?
1.<?php
2.$on_e = 1;
3.$tw_o = 2;
4.$thre_e = 3;
5.$fou_r = 4;
6.echo $on_e / $tw_o + $thre_e / $fou_r;
7.?>
a) 0.75
b) 0.05
c) 1.25
d) Error

24. What will be the output of the following PHP code ?
1.<?php
2.$On_e = 1;
3.$tw_o = 2;
4.$thre_e = 3;
5.$fou_r = 4;
6.echo $on_e / $tw_o + $thre_e / $fou_r;
7.?>
a) 0.75
b) 0.05
c) 1.25
d) Error

25. What will be the output of the following PHP code ?
1.<?php
2.echo $red;
3.?>
a) 0
b) Nothing
c) True
d) Error

26. What will be the output of the following PHP code ?
1.<?php
2.$four4 = 4;
3.$three3 = 3;
4.$two2 = 2;
5.echo $four4 + $three3 / $two2 – 1;
6.?>
a) 4.5
b) 7
c) 3.5
d) Error

27. What will be the output of the following PHP code ?
1.<?php
2.$4four = 4;
3.$3three = 3;
4.$2two = 2;
5.echo $4four + $3three / $2two – 1;
6.?>
a) 4.5
b) 7
c) 3.5
d) Error
.
28. What will be the output of the following PHP code ?
1.<?php
2.int $one = 1;
3.echo “$one”;
4.?>
a) 0
b) 1
c) $one
d) Error
.
29. What will be the output of the following PHP code ?
1.<?php
2.var $one = 1;
3.var $two = 2;
4.echo $one / $two * $one / $two * $two;
5.?>
a) 1
b) 0
c) 0.5
d) Error

30. What will be the output of the following PHP code ?
1.<?php
2.$hello = “Hello World”;
3.$bye = “Bye”;
4.echo $hello;”$bye”;
5.?>
a) Hello World
b) Bye
c) Hello worldBye
d) Error

Answers

1-d 2-c 3-b 4-b 5-c
6-a 7-b 8-a 9-d 10-d
11-b 12-a 13-c 14-b 15-a
16-d 17-b 18-a 19-d 20-c
21-d 22-d 23-c 24-a 25-b
26-a 27-d 28-d 29-d 30-a
Spread the love

Leave a Comment

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