Preview

08 - Objects, Instances of classes

 1. _______ have data (fields) and behavior (methods) and do the work in an object-oriented program. ________ are created by classes.

 2. A class defines the data (fields) and behavior (methods) for all objects of that class. You can create ____________ from the same class.

  many classes (instances of an object)

  many objects (instances of a class)

  many methods (attributes of a class)

  many attributes (methods of a class)

 3. Analyse the following example (greenfoot java interface). Which of the following statements is true?
javafoundation_wombats_bears.png

  The leaves are objects while the animals (wombats) are class methods

  The leaves and animals (wombats) are examples of attributes

  The animals (wombats) and leaves are objects

  The animals (wombats) and leaves are all class blueprints

 4. Which statement would we use to create an object from ExampleClass?

  ExampleClass exampleClass = new ExampleClass;

  ExampleClass exampleClass;

  ExampleClass exampleClass = new ExampleClass();

  ExampleClass exampleClass = ExampleClass();

 5. Is the following statement true or false?
An class is a specific instance of an object with undefined attributes. 
A class is the informal implementation, or blueprint, of the attributes
 and behaviors of a method.

  TRUE

  FALSE

 6. Is the following statement true or false?
An object is a specific instance of a class with defined attributes. 
A class is the formal implementation, or blueprint, of the attributes
 and behaviors of an object.

  TRUE

  FALSE

 7. The following provides three true statements about all objects. Statement no.3 is referring to an object's ____________.
1.An object has identity (each object is a distinct individual).
2.An object has state (it has various properties (attributes), which might change).
3.An object has behavior (it can do things and can have things done to it).

  classes

  strings

  methods

  definitions

 8. In Java, a piece of data either is a _______ data type or is an object data type.

 9. Of the following items on the list, the data types 'String', 'Random' and 'Scanner' can also be classified under 'class', where as the other ones are primitive data types.
int 
String 
long 
double
Random 
boolean 
Scanner 

  FALSE

  TRUE

 10. A class is a description of a kind of object. A programmer may define a class using Java, or may use ___________ that come in class libraries.

  data type organisers

  mathematical operators

  strings

  predefined classes

 11. Read the following and fill in the blanks.
A class is merely a plan for a possible object.
It does not by itself create any objects.
When a programmer wants to create an object the ____ operator is used with the name of the class. 

 12. What does the following code do?
public class StringTester
{

  public static void main ( String[] args )
  {
    String str1;   // str1 is a variable that may refer to an object. 
                   // The object does not exist unit the "new" is executed.
    int    len;    // len is a primitive variable of type int

    str1 = new String("Random Jottings");  // create an object of type String
                                                           
    len  = str1.length();  // invoke the object's method length()

    System.out.println("The string is " + len + " characters long");
  }

  When it is executed, the line len=str1.length(); creates an object of the class static

  When it is executed, the line str1 = new String("Random Jottings"); creates an object of the class String

  When it is executed, an object of the class String[]args is created

  When it is executed, a str1 class is created of the type 'StringTester'

 13. An object consists of both data and methods. The following image illustrates a conceptual object that is likely to be a:
object_testandtrack_example_of_java.png

  literary object

  numerical ascii based object

  string object

  database object

 14. Referring to the image above, decide if the following statement is true or false. "The picture represents an object of class String"

  FALSE

  TRUE

 15. A class is the formal implementation, or ___________, of the attributes and behaviors of an object.

  instance

  blueprint

  mandate

  charter