Java Final

Ace your homework & exams now with Quizwiz!

Polymorphism means ______________.

.that a variable of supertype can refer to a subtype object

________ is invoked to create an object.

A constructor

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

An object

What exception type does the following program throw? public class Test { public static void main(String[] args) { System.out.println(1 / 0); } }

ArithmeticException

What exception type does the following program throw? public class Test { public static void main(String[] args) { int[] list = new int[5]; System.out.println(list[5]); } }

ArrayIndexOutOfBoundsException

An instance of _________ describes system errors. If this type of error occurs, there is little you can do beyond notifying the user and trying to terminate the program gracefully.

Error

An instance of _________ describes the errors caused by your program and external circumstances. These errors can be caught and handled by your program.

Exception

Which class contains the method for checking whether a file exists?

File

What is displayed by the following statement? System.out.println("Java is neat".replaceAll("is", "AAA"));

Java AAA neat

Which class do you use to write data into a text file?

PrintWriter

An instance of _________ describes programming errors, such as bad casting, accessing an out-of-bounds array, and numeric errors..

RuntimeException

Which class do you use to read data from a text file?

Scanner

Which of the following statements is preferred to create a string "Welcome to Java"?

String s = "Welcome to Java";

class Test { public static void main(String[] args) { String s; System.out.println("s is " + s); } }

The program has a compile error because s is not initialized, but it is referenced in the println statement.

What modifier should you use on a class so that a class in the same package can access it but a class in a different package cannot access it?

Use the default modifier.

A method that is associated with an individual object is called __________.

an instance method

In JDK 1.5, you may directly assign a primitive data type value to a wrapper object. This is called ______________.

auto boxing

An object is an instance of a __________.

class

The keyword __________ is required to declare a class.

class

Variables that are shared by every instances of a class are __________.

class variables

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

false, 0, null

Inheritance means ______________.

hat a class can extend another class

You can create an ArrayList using _________.

new ArrayList<>()

Which method can be used to read a whole line from the file?

nextLine

Object-oriented programming allows you to derive new classes from existing classes. This is called ____________.

nheritance

Which method can be used to write data?

print

The visibility of these modifiers increases in this order:

private, none (if no modifier is used), protected, and public.

What modifier should you use on the members of a class so that they are not accessible to another class in a different package, but are accessible to any subclasses in any package?

protected

Assume s is " abc ", the method __________ returns a new string "abc".

s.trim()

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = s1.toUpperCase(); if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else if (s1.equals(s2)) System.out.println("s1 and s2 have the same contents"); else System.out.println("s1 and s2 have different contents"); } }

s1 and s2 have different contents

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = new String("Welcome to Java!"); if (s1.equals(s2)) System.out.println("s1 and s2 have the same contents"); else System.out.println("s1 and s2 have different contents"); } }

s1 and s2 have the same contents

hat is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = new String("Welcome to Java!"); if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } }

s1 and s2 reference to different String objects

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = "Welcome to Java!"; String s2 = s1; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } }

s1 and s2 reference to the same String object

Encapsulation means ______________.

that data fields should be declared private

When invoking a method with an object argument, ___________ is passed.

the reference of the object

Which of the following is the correct statement to return a string from an array a of characters?

toString(a)

To prevent a class from being instantiated, _____________________

use the private modifier on the constructor.

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

x contains a reference to a Circle obje

Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following methods will cause the list to become [Beijing, Chicago, Singapore]?

x.add(1, "Chicago")

Invoking _________ returns the first element in an ArrayList x.

x.get(0)


Related study sets

Analyze Text Structure study island

View Set

Chapter 8 - Chemical Equations and Reactions

View Set

Fences [Introduction Notes] — 3CPE

View Set