C++/OOP Certification

OOP Certification

In an object-oriented approach, the most significant (and costly) mistakes are usually those made during the ________ phase.
Choice 1
design
Choice 2
testing
Choice 3
construction
Choice 4
analysis
Choice 5
implementation
            OO Concepts, question 1 of 24

Diagram

  
In the class diagram above, what are the three sections from top to bottom?
Choice 1
Superclass, subclasses, attributes
Choice 2
Data file, methods, subclasses
Choice 3
Class name, attributes, methods
Choice 4
Class name, methods, attributes
Choice 5
Class name, collaborators, subclass methods
            OO Concepts, question 10 of 24

Which of the following is an example of a class that is usually distributed to the client at runtime?
Choice 1
Web browser
Choice 2
Java applet
Choice 3
Root class
Choice 4
Word processor
Choice 5
Object request broker
            OO Concepts, question 11 of 24

Diagram

  
What thing could logically be represented by class B above?
Choice 1
Petal
Choice 2
Color
Choice 3
Plant
Choice 4
Pollen
Choice 5
Stem
            OO Concepts, question 12 of 24

Diagram

  
Classes often fit into standard design patterns. Which of the following describes the nature of the class shown in the diagram above?
Choice 1
A class for which there can be only one instance in an application
Choice 2
A class that can be used to represent inanimate objects like buildings or cars
Choice 3
An abstract class
Choice 4
A class that must have a superclass
Choice 5
A root class
            OO Concepts, question 13 of 24

If an application is written such that when changes are made to class A, many changes are also required in Class B, we say that these classes are highly ________.
Choice 1
cohesive
Choice 2
encapsulated
Choice 3
coupled
Choice 4
exclusive
Choice 5
independent
            OO Concepts, question 14 of 24

Objects belonging to the same class must share the same ________.
Choice 1
methods
Choice 2
children
Choice 3
data values
Choice 4
property values
Choice 5
parents
            OO Concepts, question 15 of 24

Types

  
Using the class categories above, what types could most likely be purchased from third party vendors?
Choice 1
Only system and persistence classes
Choice 2
System, persistence, and some interface classes
Choice 3
Only business and interface classes
Choice 4
Only business and system classes
Choice 5
Only interface classes
            OO Concepts, question 16 of 24

In most cases, a benefit of inheritance is that it ________.
Choice 1
reduces network traffic
Choice 2
eliminates redundant classes
Choice 3
reduces work
Choice 4
enhances security
Choice 5
increases program execution speed
            OO Concepts, question 17 of 24

Diagram

  
Which statement best describes the relationships shown above?
Choice 1
A person must be part of one or more teams.
Choice 2
Teams are composed of zero or more persons.
Choice 3
Teams are always made up of one or more persons and can include any number of subteams.
Choice 4
Teams always have one or more subteams and zero or more persons.
Choice 5
A team can consist of one or more persons or one or more teams.
            OO Concepts, question 19 of 24

Diagram

  
The following methods could logically be defined in abstract class "shape" above EXCEPT ________.
Choice 1
fill
Choice 2
draw
Choice 3
setRadius
Choice 4
rotate
Choice 5
scale
            OO Concepts, question 2 of 24

A system will model 100 different species. To start, you need a template defining common attributes and methods, though the methods may be implemented differently for each species. What type of class could you create?
Choice 1
Persistent
Choice 2
Abstract
Choice 3
Static
Choice 4
Super
Choice 5
Transient
            OO Concepts, question 20 of 24

Diagram

  
To increase maintainability, methods invoked by other methods inside class A should NOT send messages directly to which of the above classes?
Choice 1
Class B only
Choice 2
Class C only
Choice 3
Classes D and E only
Choice 4
Classes C, D, and E only
Choice 5
Classes B, C, D, and E
            OO Concepts, question 21 of 24

Which of the following will enhance an application's ability to be maintained?
Choice 1
Eliminating abstract classes
Choice 2
Maximizing attributes and methods per class
Choice 3
Mandatory accessor (getter and setter) methods to provide access to attributes
Choice 4
Declaring all attributes as class variables
Choice 5
Minimizing methods per class by making methods longer
            OO Concepts, question 22 of 24

Coupling occurs when a change in one class requires changes in other classes. An example of this is _____________.
Choice 1
encapsulation
Choice 2
inheritance
Choice 3
overloading methods
Choice 4
many classes
Choice 5
abstraction
            OO Concepts, question 23 of 24

Diagram

  
Given the above, in the language of object-oriented programming we would say that class C ________ the interface defined in class B.
Choice 1
inherits
Choice 2
overrides
Choice 3
covers
Choice 4
copies
Choice 5
repeats
            OO Concepts, question 24 of 24

When developing classes that model business logic that will be stored in a database, it is usually appropriate to ________.
Choice 1
define the attributes of the class that will make up the primary key in an abstract class
Choice 2
define the attributes of the class that will make up the primary key as class attributes
Choice 3
use standard classes to create and delete database records, but build update and select statements into the business class
Choice 4
incorporate the basic CRUD (create, retrieve, update, delete) statements in methods within each business class
Choice 5
ensure that the business classes have no knowledge about how they are stored
            OO Concepts, question 3 of 24

Dragon

  
Dragons, like the one above, have wings like a bird and scales like a lizard. In object-oriented lingo, we would say that this is an example of ________.
Choice 1
inheritance
Choice 2
multiple inheritance
Choice 3
encapsulation
Choice 4
aggregation
Choice 5
polymorphism
            OO Concepts, question 4 of 24

Aside from a prototype, what is the next best thing to satisfy a user who really wants to know what an application will be like?
Choice 1
A process model
Choice 2
A data-flow diagram
Choice 3
A class-state diagram
Choice 4
A class diagram
Choice 5
A visual storyboard
            OO Concepts, question 5 of 24

When designing methods for a class, it is generally preferable to ________.
Choice 1
have a few complex methods rather than too many small methods
Choice 2
modify superclass methods directly rather than overriding to accommodate special circumstances
Choice 3
override methods of the superclass even if the superclass version is adequate
Choice 4
have a lot of small concise methods rather than a small number of complex methods
Choice 5
name the methods differently from those of other, similar classes to prevent confusion
            OO Concepts, question 6 of 24

Consider splitting a class into several classes when it ________.
Choice 1
has more than ten class variables
Choice 2
uses multiple inheritance
Choice 3
has more than two or three subclasses
Choice 4
contains overloaded methods
Choice 5
contains cohesive subsets of related behavior
            OO Concepts, question 7 of 24

Diagram

  
What attributes does a class C object contain?
Choice 1
Weight
Choice 2
Height, width, and weight
Choice 3
Name, height, width, and weight
Choice 4
Name, idNumber, height, width, and weight
Choice 5
Weight and age
            OO Concepts, question 8 of 24

Diagram

  
A state diagram, like the one above, shows how the various methods of an object change its state. This kind of diagram could help you with which of the following?
Choice 1
design your data model
Choice 2
understand the relationships between classes
Choice 3
identify and define the methods of a class
Choice 4
identify abstract classes
Choice 5
enforce polymorphism in your design
            OO Concepts, question 9 of 24

C++ Certification

Code
const double *pc; 
Referring to the code sample above, which of the following statements is true?
Choice 1
The value of the object addressed by "pc" can be modified through pc.
Choice 2
The address of the object which contains the value of pc can be modified through "pc".
Choice 3
"pc" can reference an array of double.
Choice 4
"pc" is an array of double objects.
Choice 5
"pc" represents an array of objects of the type float.
            C++, question 1 of 40

Code
class array {
  int a[10];
  void check_index(const int index);
};
void array::check_index(const int index) { exit(1);}
main() { 
  array A;
  A.check_index(10);
What is wrong with the sample code above?
Choice 1
int a[10]; is an incorrect call. The array size must be set using an enum.
Choice 2
"class array" must be defined as "Class Array".
Choice 3
check_index is a friend function, therefore it can only be called by other member functions of the class array.
Choice 4
The object A declared in main() is being called incorrectly.
Choice 5
check_index can only be called by other member functions of the class array.
            C++, question 10 of 40

Code
class numbers {
 int I;
public:
 void set(int v) {I = v;}
 int read() {return I;}
}; 
Referring to the sample code above, what type of function is set()?
Choice 1
A void function
Choice 2
A null function
Choice 3
A member function
Choice 4
A class function
Choice 5
A local function
            C++, question 11 of 40

Which set of preprocessor directives is used to prevent multiple inclusions of header files?
Choice 1
#ifdefined and #enddefine
Choice 2
#$if and #endif
Choice 3
#define and #endif only
Choice 4
#ifndef, #define and #endif
Choice 5
#if and #define
            C++, question 12 of 40

Code
class SomeClass 
{
  const int z = 10;
}; 
What is wrong with the definition of "SomeClass" in the sample code above?
Choice 1
It contains no non-const data members.
Choice 2
A const member is initialized in the class definition, and that is not allowed.
Choice 3
Either a default constructor or copy constructor is required, and neither appear in the code above.
Choice 4
It has no access specifier.
Choice 5
It has no constructors.
            C++, question 13 of 40

Code
class X 
{
private:
 int a;
public:
 X(){cout<<"X constructor was called"<<endl;}
 ~X(){cout<<"X destructor was called"<<endl;}
} ; 
Referring to the sample code above, what is constructor X() considered to be?
Choice 1
A default constructor
Choice 2
Required to be public
Choice 3
A copy constructor
Choice 4
A virtual constructor
Choice 5
Required in a class definition
            C++, question 14 of 40

Which of the following defines a class with a static data member and correctly initializes it?
Choice 1
class bad {int I=99;};
int bad::I=99;
Choice 2
class bad {static int I = 99;};
Choice 3
class bad {static I};
int bad:I=99;
Choice 4
class bad {static int I};
int bad::I=99;
Choice 5
class bad {static int I=99;};
int I::bad=99;
            C++, question 15 of 40

Which of the following is a C++ mechanism for initializing objects?
Choice 1
Constructor
Choice 2
ObjInit
Choice 3
Member functions
Choice 4
InitObj
Choice 5
ObjBuild
            C++, question 16 of 40

Code
class Tree 
{
public:
  class TreeNode {};
} ;
TreeNode *root; 
What is the error in the sample code above?
Choice 1
TreeNode is out of scope.
Choice 2
The scope of Tree is global.
Choice 3
There are no data members declared in the class.
Choice 4
There is no destructor.
Choice 5
There is nothing wrong with the code.
            C++, question 17 of 40

Code
class Grandpa
{
} ;
class Ma : public Grandpa
{
} ;
class Pa : virtual public Grandpa
{
} ;
class Me : public Ma, public Pa, virtual public Grandpa
{
} ; 
Each instance of Me will contain how many instances of Grandpa?
Choice 1
1
Choice 2
2
Choice 3
3
Choice 4
4
Choice 5
5
            C++, question 18 of 40

Polymorphism is implemented through which mechanism?
Choice 1
Late Binding
Choice 2
Early interpretation
Choice 3
Late interpretation
Choice 4
Early Binding
Choice 5
Early resolution
            C++, question 19 of 40

Code
class Word 
{
public:
  Word(const char*, int=0);
}; 
Referring to the sample code above, what is the minimum number of arguments required to call the constructor?
Choice 1
0
Choice 2
1
Choice 3
2
Choice 4
3
Choice 5
4
            C++, question 2 of 40

Code
int acnt=0;
switch (ch) { case 'a': ++acnt;
              case 'e': ++acnt;
              case 'I': ++acnt;
             } 
Assuming the value of ch is "a", what will be the value of "acnt" after the block of code is executed?
Choice 1
0
Choice 2
1
Choice 3
2
Choice 4
3
Choice 5
4
            C++, question 20 of 40

Code
int main() 
{
  int *p;
  int q;
  p = new int;
  delete q;
  return 0 ;
What is wrong with the sample code above?
Choice 1
p cannot be initialized to new int since p is an integer pointer.
Choice 2
p has to be declared as a float for this code to work properly.
Choice 3
q cannot be deleted since q is not a pointer.
Choice 4
int q; is an invalid declaration.
Choice 5
p has to be declared as a double for this code to work properly.
            C++, question 21 of 40

Code
class C 
{
  int c1, c2;
public:
  C(int a1, int a2)
          {
            c1=a1;
            c2=a2;
          }
} ; 
Which of the following is equivalent to the constructor shown above?
Choice 1
C(int a1, int a2)==c1(a1),c2(a2){}
Choice 2
C(int a1, int a2):c1(a1),c2(a2){}
Choice 3
C{(int a1, int a2)}
Choice 4
C(int a1, int a2)*c1(a1),c2(a2){}
Choice 5
C(int a1, int a2);;c1(a1),c2(a2){}
            C++, question 22 of 40

Which of the following statements about function overloading is true?
Choice 1
You CANNOT overload a function by creating another function with a different signature.
Choice 2
Function overloading is a mechanism for implementing inheritance in C++.
Choice 3
Function overloading is a mechanism for implementing polymorphism in C++.
Choice 4
You can overload two functions by giving them different names.
Choice 5
You CANNOT overload two functions that have the same signature and name but different return types.
            C++, question 23 of 40

Code
char *pointer = new char [20] ; 
Which of the following should you use to free the memory allocated by the statement above?
Choice 1
delete pointer ;
Choice 2
delete pointer [20] ;
Choice 3
delete [20] pointer ;
Choice 4
delete [] pointer ;
Choice 5
delete pointer [] ;
            C++, question 24 of 40

Code
class Golfers    
{
public :
  void Golfers();
  void ~Golfers();
}; 
In the class declaration above, what does "void ~Golfers();" represent?
Choice 1
A constructor
Choice 2
A multiple polymorphism
Choice 3
A destructor
Choice 4
A functionoid
Choice 5
A single polymorphism
            C++, question 25 of 40

Code
switch (category)
{
case 1: percentage_rate = 10.0 ;
case 2: percentage_rate = 15.0 ;
case 3: percentage_rate = 20.0 ;
default: percentage_rate = 25.0 ;
Suppose you wanted to select a percentage rate based upon an integer category. The code fragment found above ________.
Choice 1
is incorrect because "case" is not placed before the values.
Choice 2
is incorrect because the case actions need to be enclosed in braces.
Choice 3
will store the same value in percentage_rate no matter what the value of category is.
Choice 4
is incorrect because a select statement should be used instead of switch.
Choice 5
will work in most cases.
            C++, question 26 of 40

Code
class X 
{
private:
 int a;
public:
 X(){cout<<"X constructor was called"<<endl;}
 X(int n) {cout<<"X(int) constructor was called"<<endl;}
 ~X(){cout<<"X destructor was called"<<endl;}
};

main()
{
X x(3);
Which of the following will be the output from the sample above?
Choice 1
X constructor was called
X(int) constructor was called
X destructor was called
Choice 2
X(int) constructor was called
X destructor was called
Choice 3
X constructor was called
X destructor was called
Choice 4
X constructor was called
X destructor was called
Choice 5
X(int) destructor was called
X destructor was called
            C++, question 27 of 40

Where can class member objects be initialized?
Choice 1
In an overloaded new operator
Choice 2
In a constructor
Choice 3
In a namespace
Choice 4
In a catch block
Choice 5
In a static initialization block
            C++, question 28 of 40

Code
string message("a");
string news=message; 
What does the declaration of "news" do in the sample code above?
Choice 1
It calls the default constructor followed by the assignment operator.
Choice 2
It calls the assignment operator only.
Choice 3
It does nothing. The declaration has been incorrectly coded.
Choice 4
It calls the copy constructor only.
Choice 5
It calls the default constructor, assignment operator, and the destructor.
            C++, question 29 of 40

If a variable can be modified in a manner that is not defined by the C++ language, you should use which of the following specifiers in the variable declaration?
Choice 1
extern
Choice 2
register
Choice 3
volatile
Choice 4
auto
Choice 5
static
            C++, question 3 of 40

Code
class Color 
{
private:
 float red,white,blue;
public:
 Color(){red=white=blue=0.0;}
}; 
Referring to the sample code above, which of the following will correctly declare a Color object?
Choice 1
Color c1(1);
Choice 2
Color c1(red);
Choice 3
Color c1(Color::red);
Choice 4
Color c1(1.00)
Choice 5
Color c1;
            C++, question 30 of 40

What is the purpose of a member initialization list?
Choice 1
To create objects dynamically.
Choice 2
To assign values to global variables.
Choice 3
To create an array of objects.
Choice 4
To allow arguments to be passed to member constructors.
Choice 5
To reduce memory requirements for programs.
            C++, question 31 of 40

Code
class mybase {};
class derived1 {};
class derived2:public mybase,derived1{}; 
Which of the following statements about "derived2" is true in reference to the sample code above?
Choice 1
derived2 uses public inheritance for mybase and public inheritance for derived1.
Choice 2
The declaration of "derived2" is invalid because either derived or mybase must be virtual
Choice 3
derived2 uses public inheritance for mybase and private inheritance for derived1.
Choice 4
The declaration of "derived2" is invalid because "derived1" must have an access specifier.
Choice 5
The declaration of "derived2" is invalid because "derived2" can only inherit from one class.
            C++, question 32 of 40

Code
class Parent
{
} ;
class Child : public Parent 
{
} ;
Child *c = new Child ;
Parent *p = c ; 
What does the assignment statement above need in order to be legal?
Choice 1
A cast operator to Parent defined for Child.
Choice 2
A dynamic_cast from Child to Parent.
Choice 3
A static_cast from Child to Parent.
Choice 4
(Parent *) to cast the pointer c.
Choice 5
Nothing.
            C++, question 33 of 40

When does dynamic binding occur?
Choice 1
During linking.
Choice 2
During construction.
Choice 3
During execution.
Choice 4
During compilation.
Choice 5
During encapsulation.
            C++, question 34 of 40

Code
class myclass { 
public:
  myclass(int x);
};
myclass::myclass(int x) { a=x;}
int main() 

  myclass ob(120);
  myclass *p;
  return 0;
Referring to the sample code above, which of the following would you use to initialize the value of p to the address of the object ob?
Choice 1
p=ob;
Choice 2
p=*ob;
Choice 3
*p=*ob;
Choice 4
p=&ob;
Choice 5
*p=myclass *ob;
            C++, question 35 of 40

Code
class myclass 

  int a, b;
public:
  myclass(int n, int m) {a=n, b=m;} 
What is the constructor definition in the sample code above equivalent to?
Choice 1
myclass() {a=m, b=n;}
Choice 2
myclass(int n, int m) {a=n+m, b=m+n;}
Choice 3
myclass(int n, int m) {a=m, b=n;{this->a=n,this->b=m;}}
Choice 4
myclass(int n,int m) {this->a=n,this->b=m;}
Choice 5
myclass() {this->a=n,this->b=m;} {a=0, b=0;}
            C++, question 36 of 40

Code
class ci { 
  int I;
public:
  ci (int j) {I=j;}
  ci (ci &rv) { I=rv.I;}
};
main() { 
  ci original(1);
  ci x1(original); 
  ci x2 = original;
Referring to the sample code above, what initializes the object x1?
Choice 1
Bitwise copying.
Choice 2
A cast.
Choice 3
The default constructor.
Choice 4
The copy constructor.
Choice 5
The default copy constructor.
            C++, question 37 of 40

Code
class professor {};
class teacher : public virtual professor {};
class researcher : public virtual professor {};
class myprofessor : public teacher, public researcher {};
 
Referring to the sample code above, if an object of class "myprofessor" were created, how many instances of professor will it contain?
Choice 1
0
Choice 2
1
Choice 3
2
Choice 4
3
Choice 5
4
            C++, question 38 of 40

Code
class Stock_trader 
{
  int Stock_trader();
}; 
What is wrong with the class Stock_trader declaration in the sample code above?
Choice 1
It has no access specifiers.
Choice 2
Constructors have to be declared as protected.
Choice 3
The closing braces "}" appear too early in the class declaration.
Choice 4
Constructors cannot have return values.
Choice 5
The scope resolution operator has not been utilized in the class declaration.
            C++, question 39 of 40

Code
class tailor : public virtual worker 
{
/*..*/
}; 
Referring to the sample code above, which of the following statements is true?
Choice 1
"worker" and "tailor" are protected virtually.
Choice 2
"worker" and "tailor" are public to each other.
Choice 3
"worker" is a virtual base class of "tailor"
Choice 4
"tailor" is a virtual member of the class "worker".
Choice 5
"tailor" is a base class for a virtual "worker".
            C++, question 4 of 40

Code
class SomeClass
{
  int x ;
public:
  SomeClass (int xx) : x(xx) {} ;
} ;
SomeClass x (10) ;
SomeClass y(x) ; 
What is wrong with the initialization of y in the sample code above?
Choice 1
It is illegal because SomeClass has no public copy constructor.
Choice 2
There is nothing wrong with the initialization of y. It is perfectly legal.
Choice 3
It is illegal because SomeClass has no default constructor.
Choice 4
It is illegal because SomeClass has no copy constructor.
Choice 5
It is illegal because SomeClass has no virtual destructor.
            C++, question 40 of 40

1