Quiz 4 Study questions #1

¡Supera tus tareas y exámenes ahora con Quizwiz!

___________ represents an entity in the real world that can be distinctly identified.

An object

Analyze the following code: public class Test { public static void main(String[] args) { double radius; final double PI= 3.15169; double area = radius * radius * PI; System.out.println("Area is " + area); }

The program has compile errors because the variable radius is not initialized.

_____________ is invoked to create an object.

A constructor

An object is an instance of a _________.

class

They keyword ___________ is required to declare a class.

class

Given the declaration Circle x = new Circle(), which of the following statement is most accurate.

x contains a reference to a Circle object.

Which of the following code A or B, or both creates an object of the Date class: A: public class Test { public Test() { new java.util.Date(); } } B: public class Test { public Test() { java.util.Date date = new java.util.Date(); } }

A and B

___________ is a construct that defines objects of the same type.

A class

Which of the following statements are true? A. A default constructor is provided automatically if no constructors are explicitly declared in the class. B. At least one constructor must always be defined explicitly. C. Every class has a default constructor. D. The default constructor is a no-arg constructor.

A- A default constructor is provided automatically if no constructors are explicitly declared in the class. D- The default constructor is a no-arg constructor.

Which of the following statements are true? A. Local variables do not have default values. B. Data fields have default values. C. A variable of a primitive type holds a value of the primitive type. D. A variable of a reference type holds a reference to where an object is stored in the memory. E. You may assign an int value to a reference variable.

ABCD

Which of the following statements are correct? A. A reference variable is an object. B. A reference variable references to an object. C. A data field in a class must be of a primitive type. D. A data field in a class can be of an object type

B. A reference variable references to an object. D. A data field in a class can be of an object type

Analyze the following code. public class Test { public static void main(String[] args) { int n = 2; xMethod(n); System.out.println("n is " + n); } void xMethod(int n) { n++; } } A. The code has a compile error because xMethod does not return a value. B. The code has a compile error because xMethod is not declared static. C. The code prints n is 1. D. The code prints n is 2. E. The code prints n is 3.

B. The code has a compile error because xMethod is not declared static.

Analyze the following code. class TempClass { int i; public void TempClass(int j) { int i = j; } } public class C { public static void main(String[] args) { TempClass temp = new TempClass(2); } } A. The program has a compile error because TempClass does not have a default constructor. B. The program has a compile error because TempClass does not have a constructor with an int argument. C. The program compiles fine, but it does not run because class C is not public. D. The program compiles and runs fine.

B. The program has a compile error because TempClass does not have a constructor with an int argument.

Analyze the following code: public class Test { public static void main(String[] args) { A a = new A(); a.print(); } } class A { String s; A(String s) { this.s = s; } void print() { System.out.println(s); } } A. The program has a compile error because class A is not a public class. B. The program has a compile error because class A does not have a default constructor. C. The program compiles and runs fine and prints nothing. D. The program would compile and run if you change A a = new A() to A a = new A("5").

B. The program has a compile error because class A does not have a default constructor. D. The program would compile and run if you change A a = new A() to A a = new A("5").

Suppose TestCircle and Circle in Listing 9.1 are in two separate files named TestCircle.java and Circle.java, respectively. What is the outcome of compiling TestCircle.java and then Circle.java? A. Only TestCircle.java compiles. B. Only Circle.java compiles. C. Both compile fine. D. Neither compiles successfully.

C- Both compile fine

Analyze the following code. public class Test { int x; public Test(String t) { System.out.println("Test"); } public static void main(String[] args) { Test test = new Test(); System.out.println(test.x); } } A. The program has a compile error because System.out.println method cannot be invoked from the constructor. B. The program has a compile error because x has not been initialized. C. The program has a compile error because you cannot create an object from the class that defines the object. D. The program has a compile error because Test does not have a default constructor.

D. The program has a compile error because Test does not have a default constructor.

Variables that are shared by every instance of a class are __________. A. public variables B. private variables C. instance variables D. class variables

D. class variables

To declare a constant MAX_LENGTH as a member of the class, you write A. final static MAX_LENGTH = 99.98; B. final static float MAX_LENGTH = 99.98; C. static double MAX_LENGTH = 99.98; D. final double MAX_LENGTH = 99.98; E. final static double MAX_LENGTH = 99.98;

E. final static double MAX_LENGTH = 99.98;

You should add the static keyword in the place of ? in Line ________ in the following code: 1 public class Test { 2 private int age; 3 4 public ? int square(int n) { 5 return n * n; 6 } 7 8 public ? int getAge() { 9 return age; 10 } 11 }

In line 4

Analyze the following code. public class Test { int x; public Test(String t) { System.out.println("Test"); } public static void main(String[] args) { Test test = null; System.out.println(test.x); } }

The program has a runtime NullPointerException because test is null while executing test.x.

The default value for data field of a boolean type, numeric type, object type is ___________, respectively.

false, 0, null

Which of the following statements are true? A. Multiple constructors can be defined in a class. B. Constructors do not have a return type, not even void. C. Constructors must have the same name as the class itself. D. Constructors are invoked using the new operator when an object is created.

ABCD - All true.

Which of the following statements are correct? A. When creating a Random object, you have to specify the seed or use the default seed. B. If two Random objects have the same seed, the sequence of the random numbers obtained from these two objects are identical. C. The nextInt() method in the Random class returns the next random int value. D. The nextDouble() method in the Random class returns the next random double value.

All correct-ABCD

A method that is associated with an individual object is called __________. A. a static method B. a class method C. an instance method D. an object method

An object method

To obtain the distance between the points (40, 50) and (5.5, 4.4), use _________. A. distance(40, 50, 5.5, 4.4) B. new Point2D(40, 50).distance(5.5, 4.4) C. new Point2D(40, 50).distance(new Point2D(5.5, 4.4)) D. new Point2D(5.5, 4.4).distance(40, 50) E. new Point2D(5.5, 4.4).distance(new Point2D(40, 50))

B. new Point2D(40, 50).distance(5.5, 4.4) C. new Point2D(40, 50).distance(new Point2D(5.5, 4.4)) D. new Point2D(5.5, 4.4).distance(40, 50) E. new Point2D(5.5, 4.4).distance(new Point2D(40, 50))


Conjuntos de estudio relacionados

Public Economics Mid Term Prep (2)

View Set

Health Class Kenosha E-School Password: *****3115

View Set

28) Developing the role of Leader

View Set

Spinal Cord and Gray and White matter

View Set

Lecture 4: Organization and Cells of the Nervous System

View Set

Find the slope and Y-intercept given a graph, table, ordered pairs or equation

View Set