chapters 9 and 10 pt 1

Beschreibung

chapters 9 and 10
Joe Delisle
Quiz von Joe Delisle, aktualisiert more than 1 year ago
Joe Delisle
Erstellt von Joe Delisle vor fast 7 Jahre
222
0

Zusammenfassung der Ressource

Frage 1

Frage
What is the output of the following code? String s = "University"; s.replace("i", "ABC"); System.out.println(s);
Antworten
  • UnABCversity
  • UnABCversABCty
  • UniversABCty
  • University

Frage 2

Frage
Which of the following is the correct statement to return a string from an array a of characters?
Antworten
  • String.toString(a)
  • convertToString(a)
  • new String(a)
  • toString(a)

Frage 3

Frage
Every instance data field f in the class can be referenced using this.f in a static method the same class.
Antworten
  • True
  • False

Frage 4

Frage
Analyze the following code.
Antworten
  • 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 has no compile errors but will get a runtime error because radius is not initialized.
  • The program compiles and runs fine.

Frage 5

Frage
The following program displays ________.
Antworten
  • Java
  • Java and HTML
  • and HTML
  • nothing is displayed

Frage 6

Frage
Which of the following are properties of a constructor?
Antworten
  • A constructor must have the same name as the class.
  • A constructor is called using the new operator.
  • Constructors may be overloaded.

Frage 7

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

Frage 8

Frage
What is the output of the following program?
Antworten
  • 1234567 1234567
  • 1234567 7654321
  • 7654321 1234567
  • 7654321 7654321

Frage 9

Frage
Which of the following statements is correct?
Antworten
  • Integer.parseInt("12", 2);
  • Integer.parseInt(100);
  • Integer.parseInt("100");
  • Integer.parseInt(100, 16);
  • Integer.parseInt("345", 8);

Frage 10

Frage
BigInteger and BigDecimal are immutable
Antworten
  • True
  • False

Frage 11

Frage
Assume StringBuilder strBuf is "ABCDEFG", after invoking ________, strBuf contains "AEFG".
Antworten
  • strBuf.delete(0, 3)
  • strBuf.delete(1, 3)
  • strBuf.delete(1, 4)
  • strBuf.delete(2, 4)

Frage 12

Frage
Assume java.util.Date[] dates = new java.util.Date[10], which of the following statements are true?
Antworten
  • dates is null.
  • dates[0] is null.
  • dates = new java.util.Date[5] is fine, which assigns a new array to dates.
  • dates = new Date() is fine, which creates a new Date object and assigns to dates.

Frage 13

Frage
The method equals, compareTo, charAt, and length are in the ________ class.
Antworten
  • String
  • StringBuffer
  • StringBuilder
  • Character

Frage 14

Frage
Every instance data field f in the class can be referenced using this.f in an instance method the same class.
Antworten
  • True
  • False

Frage 15

Frage
Which of the following is true?
Antworten
  • You can add characters into a string buffer.
  • You can delete characters into a string buffer.
  • You can reverse the characters in a string buffer.
  • The capacity of a string buffer can be automatically adjusted.

Frage 16

Frage
String s = "Welcome to Java"; s.replaceAll("a", "BB"); System.out.println(s);
Antworten
  • Welcome to Java
  • Welcome to JBBva
  • Welcome to JBBvBB
  • Welcome to JavBB

Frage 17

Frage
You can create an instance of the Math class.
Antworten
  • True
  • False

Frage 18

Frage
Which of the following can be placed in the blank line in the following code?
Antworten
  • this
  • Test

Frage 19

Frage
Which of the following statements will convert a string s into i of int type?
Antworten
  • i = Integer.parseInt(s);
  • i = (new Integer(s)).intValue();
  • i = Integer.valueOf(s).intValue();
  • i = Integer.valueOf(s);
  • i = (int)(Double.parseDouble(s));

Frage 20

Frage
What is the output of the following code?
Antworten
  • s1 and s2 reference to the same String object
  • s1 and s2 reference to different String objects

Frage 21

Frage
What is the output of Integer.parseInt("10", 2)?
Antworten
  • Invalid statement;
  • 10;
  • 2;
  • 1;

Frage 22

Frage
Which of the following statements are correct?
Antworten
  • new java.math.BigInteger("343");
  • new java.math.BigDecimal("343.445");
  • new java.math.BigInteger(343);
  • new java.math.BigDecimal(343.445);

Frage 23

Frage
________ returns a string.
Antworten
  • String.valueOf(123)
  • String.valueOf(12.53)
  • String.valueOf(false)
  • String.valueOf(new char[]{'a', 'b', 'c'})

Frage 24

Frage
Suppose s1 and s2 are two strings. Which of the following statements or expressions are incorrect?
Antworten
  • String s = new String("new string");
  • String s3 = s1 + s2
  • s1 >= s2
  • int i = s1.length
  • s1.charAt(0) = '5'

Frage 25

Frage
An immutable class cannot have ________.
Antworten
  • public data fields
  • private data fields
  • public constructors
  • no-arg constructors
  • static data fields

Frage 26

Frage
Suppose TestCircle1 and Circle1 in Listing 9.1 are in two separate files named TestCircle1.java and Circle1.java, respectively. What is the outcome of compiling TestCircle.java and then Circle.java?
Antworten
  • Only TestCircle1.java compiles.
  • Only Circle1.java compiles.
  • Both compile fine.
  • Neither compiles successfully.

Frage 27

Frage
Suppose the xMethod() is invoked from a main method in a class as follows, xMethod() is ________ in the class.
Antworten
  • a static method
  • an instance method
  • a static method or an instance method

Frage 28

Frage
________ returns the last character in a StringBuilder variable named strBuf?
Antworten
  • strBuf.charAt(strBuf.length() - 1)
  • strBuf.charAt(strBuf.capacity() - 1)
  • StringBuilder.charAt(strBuf.length() - 1)
  • StringBuilder.charAt(strBuf.capacity() - 1)

Frage 29

Frage
You can always use the default constructor even though the non-default constructors are defined in the class.
Antworten
  • True
  • False

Frage 30

Frage
All local variables in a method have default values.
Antworten
  • True
  • False

Frage 31

Frage
In JDK 1.5, you may directly assign a primitive data type value to a wrapper object. This is called ________.
Antworten
  • auto boxing
  • auto unboxing
  • auto conversion
  • auto casting

Frage 32

Frage
The replace method in the String class replaces a character in the string. So it does change the content of the string.
Antworten
  • True
  • False

Frage 33

Frage
What is the printout for the third statement in the main method?
Antworten
  • j is 0
  • j is 1
  • j is 2
  • j is 3

Frage 34

Frage
What code may be filled in the blank without causing syntax or runtime errors?
Antworten
  • test.date
  • date
  • test.date.toString()
  • date.toString()

Frage 35

Frage
If the parameter is an object, both formal parameter and actual parameter reference to the same object.
Antworten
  • True
  • False

Frage 36

Frage
All local variables in a method have default values.
Antworten
  • True
  • False

Frage 37

Frage
If the parameter is of a primitive type, both formal parameter and actual parameter reference to the same memory.
Antworten
  • True
  • False

Frage 38

Frage
Which is the advantage of encapsulation?
Antworten
  • Only public methods are needed.
  • Making the class final causes no consequential changes to other code.
  • It changes the implementation without changing a class's contract and causes no consequential changes to other code.
  • It changes a class's contract without changing the implementation and causes no consequential changes to other code.

Frage 39

Frage
An object is an instance of a ________.
Antworten
  • program
  • class
  • method
  • data

Frage 40

Frage
Assume s is " abc ", the method ________ returns a new string "abc".
Antworten
  • s.trim(s)
  • trim(s)
  • String.trim(s)
  • s.trim()

Frage 41

Frage
Which of the following statements are true about an immutable object?
Antworten
  • The contents of an immutable object cannot be modified.
  • All properties of an immutable object must be private.
  • All properties of an immutable object must be of primitive types.
  • An object type property in an immutable object must also be immutable.
  • An immutable object contains no mutator methods.

Frage 42

Frage
Variables that are shared by every instances of a class are ________.
Antworten
  • class variables
  • public variables
  • private variables
  • instance variables

Frage 43

Frage
To get a string from the StringBuffer, you use the toString method.
Antworten
  • True
  • False

Frage 44

Frage
Which of the following is the correct statement to return a string from an array a of characters?
Antworten
  • toString(a)
  • new String(a)
  • convertToString(a)
  • String.toString(a)

Frage 45

Frage
A static data field can be accessed from any method in the same class.
Antworten
  • True
  • False

Frage 46

Frage
Analyze the following code:
Antworten
  • The variable t is not initialized and therefore causes errors.
  • The variable t is private and therefore cannot be accessed in the main method.
  • t is non-static and it cannot be referenced in a static context in the main method.
  • The variable x is not initialized and therefore causes errors.
  • The program compiles and runs fine.

Frage 47

Frage
You can declare variables of the same name in a method even though they are in the same block.
Antworten
  • True
  • False

Frage 48

Frage
Java uses ________ to reference the current object.
Antworten
  • this
  • that
  • thisObject
  • null

Frage 49

Frage
You should add the static keyword in the place of ? in Line ________ in the following code:
Antworten
  • in line 4
  • in line 8
  • in both line 4 and line 8
  • none

Frage 50

Frage
To create an instance of BigDecimal for 454.45, use ________.
Antworten
  • BigInteger(454.45);
  • new BigInteger(454.45);
  • BigInteger("454.45");
  • new BigDecimal("454.45");

Frage 51

Frage
What is the output of the following code?
Antworten
  • s1 and s2 reference to the same String object
  • s1 and s2 reference to different String objects

Frage 52

Frage
Analyze the following code.
Antworten
  • The code has a compile error because xMethod does not return a value.
  • The code has a compile error because xMethod is not declared static.
  • The code prints n is 1.
  • The code prints n is 2.
  • The code prints n is 3.

Frage 53

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

Frage 54

Frage
Java assigns a default value to a data member of a class if the data is not initialized.
Antworten
  • True
  • False

Frage 55

Frage
Analyze the following code:
Antworten
  • The program has a compilation error because class A is not a public class.
  • The program has a compilation error because class A does not have a default constructor.
  • The program compiles and runs fine and prints nothing.
  • The program would compile and run if you change A a = new A() to A a = new A("5").

Frage 56

Frage
Which of the following statements are true?
Antworten
  • Use the private modifier to encapsulate data fields.
  • Encapsulating data fields makes the program easy to maintain.
  • Encapsulating data fields makes the program short.
  • Encapsulating data fields helps prevent programming errors.

Frage 57

Frage
Which of the following statements is preferred to create a string "Welcome to Java"?
Antworten
  • String s = "Welcome to Java";
  • String s = new String("Welcome to Java");
  • String s; s = "Welcome to Java";
  • String s; s = new String("Welcome to Java");

Frage 58

Frage
A static data field can be accessed from any method in the same class.
Antworten
  • True
  • False

Frage 59

Frage
What code may be filled in the blank without causing syntax or runtime errors?
Antworten
  • test.date
  • date
  • test.date.toString()
  • date.toString()

Frage 60

Frage
What is displayed by the following code?
Antworten
  • A,B;C;D
  • A B C D
  • A B C;D
  • A B;C;D

Frage 61

Frage
To add BigInteger b1 to b2, you write ________.
Antworten
  • b1.add(b2);
  • b2.add(b1);
  • b2 = b1.add(b2);
  • b2 = b2.add(b1);
  • b1 = b2.add(b1);

Frage 62

Frage
Assume s is "ABCABC", the method ________ returns a new string "aBCaBC".
Antworten
  • s.toLowerCase(s)
  • s.toLowerCase()
  • s.replace('A', 'a')
  • s.replace('a', 'A')
  • s.replace("ABCABC", "aBCaBC")

Frage 63

Frage
You can declare variables of the same name in a method if they are in non-nesting blocks.
Antworten
  • True
  • False

Frage 64

Frage
Analyze the following code.
Antworten
  • 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 you cannot create an object from the class that defines the object.
  • 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.

Frage 65

Frage
What is the output of the following code?
Antworten
  • 3
  • 4
  • 10
  • 11

Frage 66

Frage
An immutable class cannot have ________.
Antworten
  • public data fields
  • private data fields
  • public constructors
  • no-arg constructors
  • static data fields

Frage 67

Frage
Assume StringBuilder strBuf is "ABCCEFC", after invoking ________, strBuf contains "ABTTEFT".
Antworten
  • strBuf.replace('C', 'T')
  • strBuf.replace("C", "T")
  • strBuf.replace("CC", "TT")
  • strBuf.replace('C', "TT")
  • strBuf.replace(2, 7, "TTEFT")

Frage 68

Frage
Assume StringBuilder strBuf is "ABCDEFG", after invoking ________, strBuf contains "ABCRRRRDEFG".
Antworten
  • strBuf.insert(1, "RRRR")
  • strBuf.insert(2, "RRRR")
  • strBuf.insert(3, "RRRR")
  • strBuf.insert(4, "RRRR")

Frage 69

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

Frage 70

Frage
Each class in the file is compiled into a separate bytecode file.
Antworten
  • True
  • False

Frage 71

Frage
Which of the following statements are true?
Antworten
  • Local variables do not have default values.
  • Data fields have default values.
  • A variable of a primitive type holds a value of the primitive type.
  • A variable of a reference type holds a reference to where an object is stored in the memory.
  • You may assign an int value to a reference variable.
Zusammenfassung anzeigen Zusammenfassung ausblenden

ähnlicher Inhalt

Computing Hardware - CPU and Memory
ollietablet123
SFDC App Builder 2
Parker Webb-Mitchell
Data Types
Jacob Sedore
Intake7 BIM L1
Stanley Chia
Software Processes
Nurul Aiman Abdu
Design Patterns
Erica Solum
CCNA Answers – CCNA Exam
Abdul Demir
Abstraction
Shannon Anderson-Rush
Spyware
Sam2
HTTPS explained with Carrier Pigeons
Shannon Anderson-Rush
Data Analytics
anelvr