The Papaer Java Test Questions and Answers

Only available on StudyMode
  • Download(s) : 895
  • Published : April 23, 2013
Open Document
Text Preview
Gaddis – Starting Out With Java 5 – From Control Structures to Objects Chapter 06 – A First Look At Classes

Multiple Choice

1. One or more objects may be created from a(n)_____.
a.field
b.class
c.method
d.instance

ANS: B

2. Class objects normally have _____ that perform useful operations on their data, but primitive variables do not. a.fields
b.instances
c.methods
d.relationships

ANS: C

3. In the cookie cutter method: Think of the _____ as a cookie cutter and _____ as the cookies. a.object; classes
b.class; objects
c.class; fields
d.field; methods

ANS: B

4. A UML diagram does not contain _____.
a.class name
b.methods
c.fields
d.object names

ANS: D

5. An access specifier indicates how the class may be accessed. a.True
b.False

ANS: A

6. Data hiding, which means that critical data stored inside the object is protected from code outside the object is accomplished in Java by _____. a.using the public access specifier on the class methods

b.using the private access specifier on the class methods
c.using the private access specifier on the class definition d.using the private access specifier on the class fields

ANS: D

7. For the following code, which statement is not true?
public class Sphere
{
private double radius;
public double x;
private double y;
private double z;
}
a.x is available to code that is written outside the Sphere class. b.radius is not available to code written outside the Sphere class. c.radius, x, y, and z are called members of the Sphere class. d.z is available to code that is written outside the Sphere class.

ANS: D

8. Which of the following is not part of the method header?
a.Method name
b.Return type
c.Access specifier
d.Parameter variable declaration
e.All of the above are parts of the method header

ANS: E

9. A method that stores a value in a class’s field or in some other way changes the value of a field is known as a mutator method. a.True
b.False

ANS: A

10. You should not define a class field that is dependent upon the values of other class fields _____. a.in order to avoid having stale data
b.because it is redundant
c.because it should be defined in another class
d.in order to keep it current

ANS: A

11. The following UML diagram entry means _____
+ setHeight(h : double) : void
a.this is a public field called Height and is a double data type b.this is a private method with no parameters and returns a double data type c.this is a private field called Height and is a double data type d.this is a public method with a parameter of data type double and does not return a value

ANS: D

12. Instance methods should be declared static.
a.True
b.False

ANS: B

13. Methods that operate on an object’s fields are called
a.instance variables
b.instance methods
c.public methods
d.private methods

ANS: B

14. The scope of a private instance field is
a.the instance methods of the same class
b.inside the class, but not inside any method
c.inside the parentheses of a method header
d.the method in which they are defined

ANS: A

15. A constructor is a method that is automatically called when an object is created. a.True
b.False

ANS: A

16. A constructor
a.always accepts two arguments
b.has return type of void
c.has the same name as the class
d.always has an access specifier of private

ANS: C

17. Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable. a.True
b.False

ANS: A

18. Which of the following statements will create a reference, str, to the String, “Hello, World”? a.String str = “Hello, World”;
b.string str = “Hello, World”;
c.String str = new “Hello, World”;
d.str = “Hello, World”;

ANS: A

19. Two or more methods in a class may have the same name as long as a.they have different return types
b.they have different parameter lists
c....
tracking img