Thursday, August 15, 2019
The Papaer Java Test Questions and Answers
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 _____. . 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? ublic 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 cl ass 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. his 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â⬠; . 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. they have different return types, but the same parameter list d. you cannot ha ve two methods with the same name ANS: B 20. Given the following code, what will be the value of finalAmount when it is displayed? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order(int orderNumber, double orderAmt, double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; rderDiscount = orderDisc; } } public class CustomerOrder { public static void main(String[] args) { int ordNum = 1234; double ordAmount = 580. 00; double discountPer = 0. 1; Order order; double finalAmount = order. orderAmount ââ¬â order. orderAmount * order. orderDiscount; System. out. println(ââ¬Å"Final order amount = $â⬠+ finalAmount); } } a. 528. 00 b. 580. 00 c. There is no value because the constructor has an error. d. There is no value because the object order has not been created. ANS: D 21. A class specifies the _____ and _____ that a particular type of object has. a. relationships; methods b. ields; object names c. field s; methods d. relationships; object names ANS: C 22. ____ refers to the combining of data and code into a single object. a. Data hiding b. Abstraction c. Object d. Encapsulation ANS: D 23. Another term for an object of a class is ____. a. access specifier b. instance c. member d. method ANS: B 24. In this book the general layout of a UML diagram is a box that is divided into three sections. The top section has the ____; the middle section holds ____; the bottom section holds ____. a. class name; fields; methods b. class name; object name; methods c. object name; fields; methods . object name; methods; fields ANS: A 25. The public access specifier for an field indicates that the field may not be accessed by statements outside the class. a. True b. False ANS: B 26. For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; } a. x is available to code that is written outside the Circle class. b. radius is not ava ilable to code written outside the Circle class. c. radius, x, and y are called members of the Circle class. d. y is available to code that is written outside the Circle class.ANS: D 27. It is common practice in object-oriented programming to make all of a classââ¬â¢s _____. a. methods private b. fields private c. fields public d. fields and methods public ANS: B 28. After the header, the body of the method appears inside a set of a. brackets, [] b. paretheses, () c. braces, {} d. double quotes, ââ¬Å"â⬠ANS: C 29. A method that gets a value from a classââ¬â¢s field but does not change it is known as a mutator method. a. True b. False ANS: B 30. In UML diagrams, a ____ indicates the member is private and a _____ indicates the member is public. a. *; / b. ; @ c. ââ¬â; + d. (); : ANS: C 31. In a UML diagram to indicate the data type of a variable enter a. the variable name followed by the data type b. the variable name followed by a colon and the data type c. the class name followed by the variable name followed by the data type d. the data type followed by the variable name ANS: B 32. Instance methods do not have the key word static in their headers. a. True b. False ANS: A 33. When an object is created, the fields associated with the object are called a. instance fields b. instance methods c. fixed fields d. class instancesANS: A 34. A constructor is a method that a. returns an object of the class. b. never receives any arguments. c. with the name (class name). constructor. d. performs initialization or setup operations. ANS: D 35. The term ââ¬Å"default constructorâ⬠is applied to any constructor that does not accept arguments. a. True b. False ANS: B 36. The scope of a public instance field is a. only the class in which it is defined b. inside the class, but not inside any method c. inside the parentheses of a method header d. the instance methods and methods outside the class ANS: D 37.When a local variable in an instance method has th e same name as an instance field, the instance field hides the local variable. a. True b. False ANS: B 38. Which of the following statements will create a reference, str, to the string, ââ¬Å"Hello, worldâ⬠? A. String str = new String(ââ¬Å"Hello, Worldâ⬠); B. String str = ââ¬Å"Hello, worldâ⬠; a. A b. B c. A and B d. Neither A or B ANS: C 39. Overloading means multiple methods in the same class a. have the same name, but different return types b. have different names, but the same parameter list c. have the same name, but different parameter lists d. perform the same function ANS: C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment