Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Inheritance in class diagrams is depicted by________(a) single-headed empty arrow(b) single-headed filled arrow(c) double-headed empty arrow(d) double-headed filled arrowThe question was asked during an interview.My question comes from Object and Design-2 topic in portion Object Tools and Design and Variables in PHP of PHP

Answer»

The correct ANSWER is (a) single-headed empty arrow

To explain: The UML describes the INHERITANCE relationship as a generalization. This relationship is signified by a line leading from the subclass to its PARENT. The line is TIPPED with an empty closed arrow.

2.

Which one of the following is displayed in the third section of the class diagram?(a) Operations(b) Inheritance(c) Abstraction(d) CouplingThe question was posed to me during an interview.I need to ask this question from Object and Design-2 in portion Object Tools and Design and Variables in PHP of PHP

Answer»

Right answer is (a) OPERATIONS

Best EXPLANATION: Operations describe methods, or more properly, they describe the CALLS that can be MADE on an instance of a class.

3.

# is the visibility code for?(a) Private(b) Friendly(c) Protected(d) StaticI had been asked this question during an interview.I need to ask this question from Object and Design-2 topic in division Object Tools and Design and Variables in PHP of PHP

Answer»

Correct OPTION is (C) Protected

Easy EXPLANATION: Available to the CURRENT CLASS and its subclasses only.

4.

A bidirectional relationship in class diagrams is described by________(a) double-headed arrow(b) visibility symbols(c) single-headed arrow(d) double diamondThis question was addressed to me in an online interview.This intriguing question originated from Object and Design-2 topic in division Object Tools and Design and Variables in PHP of PHP

Answer»

The CORRECT CHOICE is (a) double-headed arrow

Best EXPLANATION: A UNIDIRECTIONAL ASSOCIATION has single-headed arrow.

5.

Which one of the following statements is true about sequence diagrams?(a) A sequence diagram is class based(b) A sequence diagram presents the participants of a system from right to left(c) The vertical broken lines represent the lifetime of the class in the system(d) A sequence diagram is object basedThe question was posed to me in an online quiz.I need to ask this question from Object and Design-2 topic in division Object Tools and Design and Variables in PHP of PHP

Answer» CORRECT ANSWER is (d) A sequence diagram is OBJECT BASED

Best EXPLANATION: A sequence diagram is object based rather than class based. It is used to model a process in a system step by step.
6.

Which relationship is illustrated by a line that begins with an unfilled diamond?(a) Composition(b) Abstraction(c) Aggregation(d) InheritanceThe question was posed to me in class test.My enquiry is from Object and Design-2 in division Object Tools and Design and Variables in PHP of PHP

Answer»

Right option is (c) AGGREGATION

Easy EXPLANATION: In the CASE of aggregation, the contained objects are a core PART of the container, but they can also be contained by other objects at the same TIME.

7.

+ is the visibility code for?(a) Public(b) Private(c) Protected(d) FriendlyThis question was addressed to me in exam.This interesting question is from Object and Design-2 in division Object Tools and Design and Variables in PHP of PHP

Answer»

The correct OPTION is (a) Public

To ELABORATE: The visibility symbol is FOLLOWED by the NAME of the attribute.

8.

If the diamond is filled it depicts which relationship?(a) Strong Aggregation(b) Composition(c) Abstraction(d) InheritanceI have been asked this question in my homework.This intriguing question originated from Object and Design-2 topic in portion Object Tools and Design and Variables in PHP of PHP

Answer» RIGHT option is (b) Composition

For EXPLANATION: In composition, the contained OBJECT can be referenced by its container only. It should be deleted when the container is deleted.
9.

Which one of the following is displayed below the class name in the class diagrams?(a) Functions(b) Methods(c) Attributes(d) ConstraintsThis question was addressed to me during an interview.My question is based upon Object and Design-2 topic in division Object Tools and Design and Variables in PHP of PHP

Answer»

The CORRECT ANSWER is (c) Attributes

For explanation I would say: Attributes describe a class’s properties. Attributes are listed in the section DIRECTLY beneath the class name.

10.

________ are used in class diagrams to describe the way in which specific elements should be used.(a) Attributes(b) Constraints(c) Constants(d) Class NamesThis question was posed to me in examination.I want to ask this question from Object and Design-2 topic in division Object Tools and Design and Variables in PHP of PHP

Answer»

Correct CHOICE is (b) Constraints

The best explanation: The {abstract} syntax is an example of a constraint. There is no SPECIAL structure for the text between the braces; it should simply provide a short clarification of any conditions that may apply to the ELEMENT.

11.

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 FunctionsI had been asked this question in an interview for job.This interesting question is from Object and Design-1 in portion Object Tools and Design and Variables in PHP of PHP

Answer»

The correct choice is (c) Class NAME

To ELABORATE: The other two SECTIONS are OPTIONAL when no more information than the class name is known.

12.

Which one among the following means tight coupling?(a) Code Duplication(b) Inheritance(c) Encapsulation(d) PolymorphismThe question was posed to me in exam.My query is from Object and Design-1 in portion Object Tools and Design and Variables in PHP of PHP

Answer» CORRECT option is (a) Code Duplication

For explanation: Duplication is one of the great evils in code. Take a look at the instances of repetition in your system. Perhaps they BELONG together. If you change something fundamental about one ROUTINE, will the similar routines need amendment? If this is the CASE, they probably belong in the same class.
13.

UML stands for?(a) unified mailing language(b) unified modeling logo(c) undefined modeling language(d) unified modeling languageThe question was asked in an interview for internship.I'm obligated to ask this question of Object and Design-1 topic in division Object Tools and Design and Variables in PHP of PHP

Answer»

Correct answer is (d) unified modeling language

For explanation: The UML EMERGED as a standard only after long years of intellectual and BUREAUCRATIC SPARRING among the great and good of the OBJECT oriented design community.

14.

Which one of the following is known as the key to object-oriented programming?(a) Polymorphism(b) Encapsulation(c) Data Abstraction(d) OrthogonalityI got this question during an interview.The doubt is from Object and Design-1 in section Object Tools and Design and Variables in PHP of PHP

Answer» RIGHT answer is (B) Encapsulation

To explain: Encapsulation simply means the hiding of data and FUNCTIONALITY from a CLIENT.
15.

Polymorphism is also known as______(a) switch(b) overact(c) encapsulation(d) class switchingI have been asked this question at a job interview.My doubt is from Object and Design-1 in division Object Tools and Design and Variables in PHP of PHP

Answer»

Right CHOICE is (d) class switching

The explanation: POLYMORPHISM is the MAINTENANCE of multiple implementations behind a COMMON INTERFACE.

16.

______ 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) BalancingI got this question in final exam.The question is from Object and Design-1 in portion Object Tools and Design and Variables in PHP of PHP

Answer»

Right option is (b) TIGHT Coupling

Explanation: Tight coupling is by no means UNIQUE to PROCEDURAL code, THOUGH the sequential nature of such code makes it prone to the problem.

17.

________ 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) BalancingI had been asked this question in an online quiz.The doubt is from Object and Design-1 topic in division Object Tools and Design and Variables in PHP of PHP

Answer»

The correct option is (a) Orthogonal

The EXPLANATION: Orthogonality, it is argued, promotes reuse in that components can be plugged into new systems without needing any SPECIAL CONFIGURATION. Such components will have clear inputs and outputs independent of any wider CONTEXT.

18.

The extent to which proximate procedures are related to one another is known as ________(a) Coupling(b) Balancing(c) Cohesion(d) Co-relationThe question was asked during an online exam.This interesting question is from Object and Design-1 in portion Object Tools and Design and Variables in PHP of PHP

Answer»

The CORRECT answer is (C) Cohesion

Best explanation: Ideally, you should create components that share a clear responsibility. If your code spreads RELATED routines widely, you will find them harder to maintain as you have to hunt around to make changes. Our PARAM Handler classes collect related PROCEDURES into a common context.

19.

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 codeI had been asked this question during an online exam.The origin of the question is Object and Design-1 topic in portion Object Tools and Design and Variables in PHP of PHP

Answer»

Right option is (b) CLIENT code

Best EXPLANATION: Procedural code takes the form of a sequential series of commands and method calls. The controlling code TENDS to take responsibility for handling differing conditions. This top-down control can result in the development of duplications and dependencies across a project. Object-oriented code tries to minimize these dependencies by moving responsibility for handling tasks away from client code and TOWARD the objects in the system.

20.

Placing a static method for generating ________ objects in the ____________ class is convenient.(a) child parent(b) parent child(c) final static(d) static finalI had been asked this question in exam.Question is from Object and Design-1 in section Object Tools and Design and Variables in PHP of PHP

Answer»

Correct ANSWER is (a) CHILD parent

Explanation: Such a design decision does have its own consequences, HOWEVER.

21.

Which class accepts a class name or an object reference and returns an array of interface name?(a) class_implements()(b) is_subclass()(c) is_subclass_of()(d) class_interface()The question was posed to me in class test.Query is from Object Tools in section Object Tools and Design and Variables in PHP of PHP

Answer»

The correct option is (a) class_implements()

For explanation: is_subclass_of() will tell you only about CLASS inheritance RELATIONSHIPS. It will not tell you that a class IMPLEMENTS an interface.

22.

Which one of the following function should I use to find the parent class of a class?(a) get_parent_class()(b) parent_class()(c) class_parent()(d) get_class_parent()The question was asked in class test.My question is based upon Object Tools topic in chapter Object Tools and Design and Variables in PHP of PHP

Answer»

Right answer is (a) get_parent_class()

Easiest EXPLANATION: The class functions also allow US to chart INHERITANCE relationships.This function requires either an object or a class name, and it returns the name of the superclass, if any. If no such class exists, that is, if the class we are testing does not have a parent, then the function returns FALSE.

23.

What will be the output if a protected method is given as the argument to the function method_exist()?(a) Method does not exist(b) False(c) Error(d) TrueI got this question in an online quiz.I'm obligated to ask this question of Object Tools in portion Object Tools and Design and Variables in PHP of PHP

Answer»

The correct choice is (d) True

Easiest explanation: method_exists() RETURNS true for PRIVATE and protected methods as well as for PUBLIC ones. Remember that the fact that a METHOD EXISTS does not mean that it will be callable.

24.

If you call a method and it doesn’t exist it’ll cause a problem. To check the method which function will you use?(a) _method()(b) methodexists()(c) is_callable()(d) is_method()I got this question in exam.My question is taken from Object Tools in section Object Tools and Design and Variables in PHP of PHP

Answer»

Right ANSWER is (C) is_callable()

The explanation is: There is another method which you can USE – method_exists() for SIMILAR purpose.

25.

You use the get_class_methods() function to return the names of all the methods in the class. Which function will you use to print it on the screen?(a) printf()(b) print_ar(c) print_r(d) echoI had been asked this question in an international level competition.This interesting question is from Object Tools in chapter Object Tools and Design and Variables in PHP of PHP

Answer» RIGHT answer is (c) print_r

The EXPLANATION is: The function get_class_methods returns an ARRAY THEREFORE we cannot use echo.
26.

PHP 4 did not support instanceof. Instead, which function did it provide?(a) is()(b) get_class()(c) is_a()(d) is_the()I got this question in final exam.The above asked question is from Object Tools topic in chapter Object Tools and Design and Variables in PHP of PHP

Answer»

Right ANSWER is (C) is_a()

To elaborate: As of PHP 5.3 is_a() no LONGER DEPRECATED.

27.

Which one of the following will you use to check the class of an object?(a) class()(b) _class()(c) class_check()(d) get_class()I had been asked this question in a job interview.I'm obligated to ask this question of Object Tools in portion Object Tools and Design and Variables in PHP of PHP

Answer»

The correct option is (d) get_class()

EASIEST explanation: This function ACCEPTS any OBJECT as an argument and returns its CLASS name as a string.

28.

Which one of the following functions will you use to check that the class exists before you work with it?(a) class_exist()(b) class_exists()(c) exist()(d) exists_class()I had been asked this question in an interview for job.I'd like to ask this question from Object Tools in section Object Tools and Design and Variables in PHP of PHP

Answer»

Right choice is (b) class_exists()

To elaborate: The class_exists() function accepts a string representing the class to CHECK for and RETURNS a Boolean true VALUE if the class exists and false OTHERWISE.

29.

How many times can you define _________ autoload in a process?(a) once(b) twice(c) thrice(d) as many times as neededThe question was posed to me in an online interview.I'd like to ask this question from Object Tools in portion Object Tools and Design and Variables in PHP of PHP

Answer»

The correct option is (a) once

Easiest EXPLANATION: __autoload is a powerful tool, but it does have some limitations. In particular, you can only define it once in a process. If you NEED to change your AUTOLOAD function DYNAMICALLY you should look at the spl_autoload_register function, which supports that FUNCTIONALITY.

30.

Which function was introduced to help automate the inclusion of class files?(a) __load()(b) __preload()(c) __autoload()(d) __inload()I had been asked this question in an interview for internship.Query is from Object Tools in chapter Object Tools and Design and Variables in PHP of PHP

Answer»

Correct choice is (c) __autoload()

Best explanation: When the PHP engine encounters an attempt to instantiate an unknown class, it invokes the __autoload() function, passing it the class name as a string. It is up to the IMPLEMENTER to define a strategy for locating and including the MISSING class file.

31.

Which one of the following statements is true for require() and require_once()?(a) They are functions(b) They are statements(c) They’ll not work if the () is not present(d) They can not be used to require filesThis question was addressed to me in semester exam.The above asked question is from Object Tools-1 topic in portion Object Tools and Design and Variables in PHP of PHP

Answer» CORRECT answer is (b) They are statements

Best explanation: require() and require_once() are ACTUALLY statements, not functions. This means that you can omit the BRACKETS when using them.
32.

Which one of the following statements is true for include_once() and require_once()?(a) Both are exactly the same(b) include_once is used for files where as require_once() is not(c) Both Handle the errors in the same way(d) Both do not handle the errors in the same wayThis question was posed to me in an interview for job.I'd like to ask this question from Object Tools-1 topic in section Object Tools and Design and Variables in PHP of PHP

Answer»

Right choice is (d) Both do not handle the errors in the same way

For EXPLANATION I WOULD say: The only difference between the INCLUDE() and require() statements lies in their handling of errors. A file invoked using require() will bring down your entire process when you MEET an error. The same error ENCOUNTERED via a call to include() will merely generate a warning and end execution of the included file.

33.

Which symbol is used to declare nested namespaces?(a) /(b) \(c) .(d) |I have been asked this question during a job interview.The question is from Object Tools-1 in chapter Object Tools and Design and Variables in PHP of PHP

Answer» CORRECT choice is (B) \

EXPLANATION: EXAMPLE – namespace com\getinstance\util;
34.

Till which version of PHP, developers were forced to name their files in a global context?(a) PHP 4(b) PHP 5(c) PHP 5.2(d) PHP 5.3I had been asked this question in an interview for internship.Question is taken from Object Tools-1 topic in section Object Tools and Design and Variables in PHP of PHP

Answer» RIGHT choice is (d) PHP 5.3

To elaborate: If you NAMED a class ShoppingBasket, it would become instantly AVAILABLE across your system.
35.

Which one of the following is the correct way of declaring a namespace?(a) namespace my;(b) namespace my();(c) my namespace;(d) namespace(my);I had been asked this question in quiz.The question is from Object Tools-1 in section Object Tools and Design and Variables in PHP of PHP

Answer»

Correct answer is (a) namespace my;

EXPLANATION: The namespace declaration MUST be the FIRST statement in its FILE.

36.

A package is a set of related _________(a) Objects(b) Classes(c) Programs(d) FunctionsThe question was asked in an online interview.The origin of the question is Object Tools-1 topic in portion Object Tools and Design and Variables in PHP of PHP

Answer»

Right choice is (b) Classes

For explanation: A PACKAGE is a set of related classes, usually grouped together in some way. PACKAGES can be USED to SEPARATE PARTS of a system from one another.