Test 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following statements are true? (Choose three.)

Use the private modifier to encapsulate data fields. Encapsulating data fields helps prevent programming errors. Encapsulating data fields makes the program easy to maintain.

Given the declaration Circle x = new Circle(), which of the following statement is most accurate? You can assign an int value to x. x contains a reference to a Circle object. x contains an object of the Circle type. x contains an int value.

x contains a reference to a Circle object.

Which of the following statements are true? (Choose four.) A default no-arg constructor is provided automatically if no constructors are explicitly declared in the class. Constructors do not have a return type, not even void. At least one constructor must always be defined explicitly. Constructors are invoked using the new operator when an object is created. Constructors must have the same name as the class itself.

A default no-arg constructor is provided automatically if no constructors are explicitly declared in the class. Constructors do not have a return type, not even void. Constructors are invoked using the new operator when an object is created. Constructors must have the same name as the class itself

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

A class

A(n) ________ is invoked to construct an object.

A constructor

Which of the following statement is most accurate? (Choose two.) A reference variable refers to an object. An object may contain the references of other objects. A reference variable is an object. An object may contain other objects.

A reference variable refers to an object. An object may contain the references of other objects.

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

An object

What is wrong in 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); } } The program has a compilation error because TempClass does not have a default constructor. The program compiles and runs fine. The program has a compilation error because TempClass does not have a constructor with an int argument. The program compiles fine, but it does not run because class C is not public.

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

Analyze the following code: (Choose two.) 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); } }

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

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 program has a compile error because you cannot create an object from the class that defines the object. The program has a compile error because test is not initialized. The program has a compile error because x has not been initialized. The program has a compile error because Test does not have a default constructor.

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

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 no compile errors but will get a runtime error because radius is not initialized. The program has compile errors because the variable radius is not initialized. The program has a compile error because a constant PI is defined inside a method. The program compiles and runs fine.

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

An object is an instance of a ________.

class

The keyword ________ is required to declare a class.

class


Kaugnay na mga set ng pag-aaral

Life (CO specific) Master Study Guide

View Set

Patho/Pharm: Endocrine System Saunder's ?'s: MEDICATIONS

View Set