Question 1.1. (TCO 1) Which of the following would be the most appropriate choice for a method in a PhoneCharger class? (Points : 5)

Question 1.1. (TCO 1) Which of the following would be the most appropriate choice for a method in a PhoneCharger class? (Points : 5).  

Question 1.1. (TCO 1) Which of the following would be the most appropriate choice for a method in a PhoneCharger class? (Points : 5)

       Voltage()

       Manufacturer()

       Current()

       Charge()

 

 

Question 2.2. (TCO 1) Object-oriented programming generally does NOT focus on _____. (Points : 5)

       A. separating the interface from the implementation

       B. client side access to implementation details

       C. information hiding

       D. ease of program modifiability

       All of the above

       None of the above

       Only A, C, and D

 

 

Question 3.3. (TCO 2) Which of the following components of a class definition cannot be overloaded? (Points : 5)

       Public member methods

       Destructors

       Constructors

       Private member methods

       All of the above

 

 

Question 4.4. (TCO 2) Which of the following statements is/are true? (Points : 5)

       A. A default constructor is automatically created for you if you do not define one.

       B. A static method of a class can access non-static members of the class directly.

       C. An important consideration when designing a class is identifying the audience, or users, of the class.

       None of the above

       Only A and C

 

 

Question 5.5. (TCO 5) Which of the following method pairs are examples of method overloading? (Points : 5)

       A. public void Bake() ; public int Bake(int x)

       B. public int Mix(int x, int y) ; public int Mix(int y, int x)

       C. public int Shake(int x, int y) ; public int Shake(int x, int y, int z)

       All of the above

       Only A and C

 

 

Question 6.6. (TCO 1) Which of the following statements is/are false? (Points : 5)

       Abstraction is the process of ignoring the high level information about a category entity or activity, while concentrating on the “unimportant” details.

       The object oriented paradigm permits the modeling of a software system in a more natural way compared to the procedural paradigm.

       In object-oriented programming we design the program as a set of cooperating objects.

       None of the above

 

 

Question 7.7. (TCO 2) You have been tasked to create an Automobile class and your boss wants you to consider the concept of encapsulation as you design your class. Which of the following actions will you take? (Points : 5)

       Declare as many class attributes public as you can, creating accessor/mutators for each one.

       Package attributes and behaviors specific to an Automobile together.

       Make sure to include a specific implementation for a drive method that all subclasses can inherit.

       Declare the class as private.

       All of the above

 

 

Question 8.8. (TCO 2) You are given an Animal class that was designed with the concept of a black box in mind.  You need to integrate the Animal class into your own code. The first thing you need to figure out is a list of _____ and _____ that are associated with the class. The actual implementation details need not be known. (Points : 5)

       interfaces; the detailed implementations

       inputs; outputs

       private methods; accessors

       relationships; UML diagrams

 

 

Question 9.9. (TCO 2) Given a private attribute called hairColor, which of the following are proper pseudocode implementations for a getter and a setter? (Points : 5)

       string getHairColor(){return hairColor}

int setHairColor(string newHairColor){return hairColor}

       void getHairColor(){return hairColor}

void setHairColor (int newHairColor){hairColor = newHairColor}

       string getHairColor(){return hairColor}

void setHairColor (string newHairColor){hairColor = newHairColor}

       string getHairColor (){hairColor = newHairColor}

void setHairColor (string newHairColor){hairColor = newHairColor}

 

 

Question 10.10. (TCO 7) Which of the following statements is true? (Points : 5)

       Interfaces can be written across multiple files or within abstract classes, unlike classes.

       The name of an interface often begins with the prefix “interface” such as interfaceShape.

       Interfaces allow object-oriented languages to implement multiple composition.

       Interfaces can not be instantiated like a class.

 

 

Question 11.11. (TCO 7) Abstract classes may contain which of the following? (Points : 5)

       A. Abstract methods

       B. Non-abstract methods

       C. Virtual methods

       A and B

       A and C

       B and C

       A, B, and C

 

 

Question 12.12. (TCO 7) In terms of object-oriented programming, rules for the use of an application programming interface or framework can be enforced through the use of a(n) _____. (Points : 5)

       contract

       inheritance hierarchy

       has-a relationship

       object constructed with a multi-arg constructor

       All of the above

 

 

Question 13.13. (TCO 4) If you have a complete, working Employee class that has been thoroughly tested, and you wish to add an overloaded getSalary() method that can calculate the salary of a Manager which is the total of salary and bonus, how should this be accomplished? (Points : 5)

       Make a brand new class.

       Add the method to your existing Employee class.

       Add the method in the same class as the Main method.

       Derive a new Manager class from the first Employee class and add it there.

 

 

Question 14.14. (TCO 3) An Airplane class and a Jet class have what type of relationship?

(Points : 5)

       The Jet is-an Airplane.

       The Airplane is-a Jet.

       The Jet has-an Airplane

       The Airplane has-a Jet.

 

 

Question 15.15. (TCO 4) Why is it a good programming practice not to have too many layers of inherited classes? (Points : 5)

       Actually, the more the merrier

       Easy to lose track of the members in the great-grandchildren classes

       So that you know which class’ constructor will execute first

       None of the above

 

——————————————————————————-

 

 

Question 1.1. (TCO 4) Suppose class Child is derived from class Parent which in turn is derived from class GrandParent. The class Parent and GrandParent are the _____? (Points : 5)

       Predecessor classes of class Child

       Forebearer classes of class Child

       Ancestor classes of class Child

       Descendant classes of class Child

       None of the above

 

 

Question 2.2. (TCO 6) The ability to reuse objects already defined, perhaps for a different purpose, with modification appropriate to the new purpose, is referred to as: (Points : 5)

       Information hiding

       Inheritance

       Redefinition

       Overloading

 

 

Question 3.3. (TCO 4) Which of the following is not a good example of a hierarchy that could be modeled with inheritance? (Points : 5)

       Order

       Dog

       Animals

       Odd numbers

 

 

Question 4.4. (TCO 8) Data/information hiding and encapsulation improves construction and maintenance because: (Points : 5)

       Adding additional details is isolated to a single class.

       Program bugs are isolated to a single class.

       Programming to an interface makes the code more logical.

       All of the above

       None of the above

 

 

Question 5.5. (TCO 8) What are some of the characteristics of “self-documenting” code? (Points : 5)

       Logical identifier names

       Value-adding comments

       Straightforward algorithms

       All of the above

       None of the above

 

 

Question 6.6. (TCO 9) Which of the following allow a programmer to reduce the complexity of an object-oriented program? (Points : 5)

       Creating each class in a separate file

       Using namespaces as a container for logically related items

       Using namespaces to create global types

       All of the above

       None of the above

 

 

Question 7.7. (TCO 2) Given a private attribute called weight, which of the following are proper implementations for a getter and a setter? (Points : 5)

       void GetWeight(){return weight;}, void SetWeight (int weight){this.weight = weight;}

       int GetWeight (){return weight;}, int SetWeight (int weight){return weight;}

       int GetWeight (){this.weight = weight;}, void SetWeight (int weight){return weight;}

       int GetWeight (){return weight;}, void SetWeight (int weight){this.weight = weight;}

 

 

Question 8.8. (TCO 7) Which of the following declares an abstract method in an abstract class? (Points : 5)

       public abstract void CookIngredients() {}

       public void CookIngredients() {}

       public abstract void CookIngredients();

       public abstract CookIngredients();

 

 

Question 9.9. (TCO 1) Assuming a class definition of a Cat that has a default constructor and constructor that accepts three string arguments, and the appropriate properties defined, how many objects are created in the code below?

static void Main(string[] args)

{

     Cat newCatObject;

     Cat newCat = new Cat(“Cat”, “Lucy”, “Persian”);

 

     newCatObject = newCat;

     newCatObject.CatName = newCat.CatName;

}

(Points : 5)

      

       2

       4

       3

       1

 

Question 10. 10. (TCO 8) Briefly describe which elements of a class are named using Camel case rules, and what are the best practices regarding the naming of these elements. (Points : 18)

     Camel case  is a term which refers to the practice of writing compound words having one or more internal uppercase letters. The methods of a class are named using camel casing because these includes multiple words.

The best practices include:

When there are multiple words, the first word should start from small letter where as other words should start from capital letter.

For example:

int getAge();

void getElementById();

are the examples of camel case.

     

 

Question 11. 11. (TCO 2) Explain the terms Encapsulation and Data/Information Hiding in object-oriented programming. How do they differ? (Points : 18)

          Encapsulation refers to the bundling of data with the methods that operate on that data. Often that definition is misconstrued to mean that the data is somehow hidden. you can have encapsulated data that is not hidden at all.

Example:

class Person {

public String name;

}

 

Variable ‘name’ is encapsulated but not hidden.

 

 

Information hiding is the principle that users of a software component (such as a class) need to know

only the essential details of how to initialize and access the component, and do not need to know the details of the implementation.

Example:

class Person {

private String name;

pubic void setName(String newname) {

name = newname;

}

}

 

—————————————————————————–   

 

Question 12. 12. (TCO 2) Given the following program description,

 

–      identify the required classes/objects necessary to achieve the program requirements;

 

–      briefly describe any relationships that might exist between your classes; and

 

–      briefly describe the overall hierarchy of your proposed classes.

 

Program Description – You have been asked to create a program designed to take coffee orders in a coffee shop. The program must be able to take an order, assign a unique ID to the order, add any number of drinks to the order and calculate the total bill. (Points : 18)

     

     

 

Question 13. 13. (TCO 7) Briefly describe what an Interface is and how it can be used in an object-oriented program. Provide example pseudocode showing how an ICountry Interface might be constructed.  (Points : 18)

An interface is a group of related methods with empty bodies. An interface contains only the signatures of methods, properties, events or indexers. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition

A bicycle’s behavior, if specified as an interface, might appear as follows:

interface Bicycle {

 

    //  wheel revolutions per minute

    void changeCadence(int newValue);

 

    void changeGear(int newValue);

 

    void speedUp(int increment);

 

    void applyBrakes(int decrement);

}

An ICountry Interface might be constructed using keyword interface. E.g

Interface iCountry{

}   

 

Question 1. 1.

(TCO 2) Keeping in mind all object-oriented programming best practices, create a class for a Chair, with the following specifications:

 

1)     Specify two data members

 

2)     Default Constructor

 

3)     Overloaded Constructor which takes both data member values as input.

 

4)     Generate a unique identification number for each object instantiated from this class.  Use a static data member to keep track of the identification number last assigned to an object so that duplications will not occur. Code the necessary portion of the class definition so as to support this requirement.

public class Chair {
    int numLegs ;
    String make ;
    int id ;
    static int count = 0;
    public Chair() {
        id = count ;
        count ++;
    }

    public Chair( int numLegs, String make) {
        this . numLegs = numLegs;
        this . make = make;
         id = count ;
        count ++;
    }

}

 

5)     Show a statement which instantiates an object of this class using the overloaded constructor.

 

You do not need to provide any accessor/mutator methods or other methods.

 

(Points : 22)

     

     Chair chair = new Chair(4,”xyz”);

 

 

Question 2. 2. (TCO 3) How does the “is-a” relationship relate to inheritance? Give an example of such a relationship.  (Points : 18)

     

      Allowing a class to contain object instances in other classes so they can be used to perform actions relate d to

the class (an “has a” relationship ) i.e., a person has the ability to walk.

 

 

Question 3. 3. (TCO 4) Consider the class Employee. Given your knowledge of some common components of employees

 

–       show a class hierarchy in which the class Employee inherits from other classes, which, in turn, can also be inherited from yet other classes; 

Class Person

Class  BoardOfDirectors : public Person

Class employee : public Person

 

–       discuss inheritance from class Employee for other closely related derived classes; and

Class FullTime : public Employee

Class PartTime : public Employee

 

–       discuss the common components of class Employee. (Points : 18)

     

String SSN; //ssn of employee

String firstname;         //first name of employee

String lastname;          //last name of employee

String department;      //department of employee

Date DOJ;                   //date of joining

Double payrate;           //pay rate of employee

The above are some components of employee class

Question 1.1. (TCO 1) Which of the following would be the most appropriate choice for a method in a PhoneCharger class? (Points : 5)