Lab 2 – Simple Class

Post Test

 

 

Lab Section:

 

Name:

 

 

Knowledge/Memory

 

1.      What attributes do all real world objects have?

a.       Existence

b.      State and behavior

c.       Size and weight

d.      Identity, state, and behavior

 

Answer: d

 

2.      To instruct a class or an object to perform a task, you need to:

a.       Send a method to it.

b.      Send a message to it.

c.       Send an instance to it.

d.      Send a state to it.

 

Answer: b

 

3.      Which of the following declarations is the general scheme for a class definition?

 
a. class ClassName{
   
  // Description of the instance variables.
  // Description of the constructors.
  // Description of the methods.
   }
 

b.  class ClassName{

  
  // Description of the methods.
  // Description of the constructors.
  // Description of the instance variables.  
  }
 
c. ClassName{
   
  // Description of the instance variables.
  // Description of the constructors.
  // Description of the methods.
   }
 
d. class ClassName{
   
  public static void main ( String[] args )
  {
     // entire program goes here
  }
   }
 
Answer: a

 

4.      When you run a Java application by typing java someClass, what is the first method that starts?

 

a.  The run() method of someClass

b.      The main() method of someClass    

c.  The someClass method

d.  None of the above

 

Answer: b

 

5.      What is another name for creating an object?

 

a.       inheritance

b.      insubordination

c.       initialization

d.      instantiation

 

Answer: d

 

Comprehension:

 

6.      What is the relationship between an object and a class?

 

a.       An object and a class are the same thing.

b.      A class is an instance of an object.

c.       An object is an instance of a class.

d.      An object is a template for a class.

 

Answer: c

 

7.      Which of the following statements best describes inheritance?

a.       Inheritance is the process of creating a new object.

b.      Inheritance is used to organize a program for maintainability.

c.       Inheritance is used when you need to create many objects of the same type.

d.      Inheritance is used to design two or more entities that are different but share many common features.

 

 

Answer: d

 

 

8. How many objects of a given class may be constructed in an application?

 

a.       As many objects as needed by the application

b.      One object per application

c.       One object per constructor

d.      One object per class

 

Answer:  a

 

9. Which of the following names do not make a good class name?

I.        Employee

II. Uncle John

III. Eat

IV. Student

 

a.  I & II  

b.  II & III

c.  I & IV

d.  III & IV

 

Answer:  b

 

Application

 

10.  In the code listed below, identify the class constructor.

 

public class House {

 

private double price;

 

public House(){

  price = 0.0;

}

 

public newHouse(){

  price = 0.0;

}

 

public void setPrice(double newPrice){

  price=newprice;

  }

 

public double getPrice(){

  return price;

  }

}

 

a.              public void setPrice(double newPrice)

b.              public double getPrice()

c.              public House()

d.              public newHouse()

 

Answer:  c