chapters 9 and 10 pt 1

Descrição

chapters 9 and 10
Joe Delisle
Quiz por Joe Delisle, atualizado more than 1 year ago
Joe Delisle
Criado por Joe Delisle mais de 6 anos atrás
219
0

Resumo de Recurso

Questão 1

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

Questão 2

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

Questão 3

Questão
Every instance data field f in the class can be referenced using this.f in a static method the same class.
Responda
  • True
  • False

Questão 4

Questão
Analyze the following code.
Responda
  • 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.

Questão 5

Questão
The following program displays ________.
Responda
  • Java
  • Java and HTML
  • and HTML
  • nothing is displayed

Questão 6

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

Questão 7

Questão
Which of the following statements are true?
Responda
  • 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.

Questão 8

Questão
What is the output of the following program?
Responda
  • 1234567 1234567
  • 1234567 7654321
  • 7654321 1234567
  • 7654321 7654321

Questão 9

Questão
Which of the following statements is correct?
Responda
  • Integer.parseInt("12", 2);
  • Integer.parseInt(100);
  • Integer.parseInt("100");
  • Integer.parseInt(100, 16);
  • Integer.parseInt("345", 8);

Questão 10

Questão
BigInteger and BigDecimal are immutable
Responda
  • True
  • False

Questão 11

Questão
Assume StringBuilder strBuf is "ABCDEFG", after invoking ________, strBuf contains "AEFG".
Responda
  • strBuf.delete(0, 3)
  • strBuf.delete(1, 3)
  • strBuf.delete(1, 4)
  • strBuf.delete(2, 4)

Questão 12

Questão
Assume java.util.Date[] dates = new java.util.Date[10], which of the following statements are true?
Responda
  • 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.

Questão 13

Questão
The method equals, compareTo, charAt, and length are in the ________ class.
Responda
  • String
  • StringBuffer
  • StringBuilder
  • Character

Questão 14

Questão
Every instance data field f in the class can be referenced using this.f in an instance method the same class.
Responda
  • True
  • False

Questão 15

Questão
Which of the following is true?
Responda
  • 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.

Questão 16

Questão
String s = "Welcome to Java"; s.replaceAll("a", "BB"); System.out.println(s);
Responda
  • Welcome to Java
  • Welcome to JBBva
  • Welcome to JBBvBB
  • Welcome to JavBB

Questão 17

Questão
You can create an instance of the Math class.
Responda
  • True
  • False

Questão 18

Questão
Which of the following can be placed in the blank line in the following code?
Responda
  • this
  • Test

Questão 19

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

Questão 20

Questão
What is the output of the following code?
Responda
  • s1 and s2 reference to the same String object
  • s1 and s2 reference to different String objects

Questão 21

Questão
What is the output of Integer.parseInt("10", 2)?
Responda
  • Invalid statement;
  • 10;
  • 2;
  • 1;

Questão 22

Questão
Which of the following statements are correct?
Responda
  • new java.math.BigInteger("343");
  • new java.math.BigDecimal("343.445");
  • new java.math.BigInteger(343);
  • new java.math.BigDecimal(343.445);

Questão 23

Questão
________ returns a string.
Responda
  • String.valueOf(123)
  • String.valueOf(12.53)
  • String.valueOf(false)
  • String.valueOf(new char[]{'a', 'b', 'c'})

Questão 24

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

Questão 25

Questão
An immutable class cannot have ________.
Responda
  • public data fields
  • private data fields
  • public constructors
  • no-arg constructors
  • static data fields

Questão 26

Questão
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?
Responda
  • Only TestCircle1.java compiles.
  • Only Circle1.java compiles.
  • Both compile fine.
  • Neither compiles successfully.

Questão 27

Questão
Suppose the xMethod() is invoked from a main method in a class as follows, xMethod() is ________ in the class.
Responda
  • a static method
  • an instance method
  • a static method or an instance method

Questão 28

Questão
________ returns the last character in a StringBuilder variable named strBuf?
Responda
  • strBuf.charAt(strBuf.length() - 1)
  • strBuf.charAt(strBuf.capacity() - 1)
  • StringBuilder.charAt(strBuf.length() - 1)
  • StringBuilder.charAt(strBuf.capacity() - 1)

Questão 29

Questão
You can always use the default constructor even though the non-default constructors are defined in the class.
Responda
  • True
  • False

Questão 30

Questão
All local variables in a method have default values.
Responda
  • True
  • False

Questão 31

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

Questão 32

Questão
The replace method in the String class replaces a character in the string. So it does change the content of the string.
Responda
  • True
  • False

Questão 33

Questão
What is the printout for the third statement in the main method?
Responda
  • j is 0
  • j is 1
  • j is 2
  • j is 3

Questão 34

Questão
What code may be filled in the blank without causing syntax or runtime errors?
Responda
  • test.date
  • date
  • test.date.toString()
  • date.toString()

Questão 35

Questão
If the parameter is an object, both formal parameter and actual parameter reference to the same object.
Responda
  • True
  • False

Questão 36

Questão
All local variables in a method have default values.
Responda
  • True
  • False

Questão 37

Questão
If the parameter is of a primitive type, both formal parameter and actual parameter reference to the same memory.
Responda
  • True
  • False

Questão 38

Questão
Which is the advantage of encapsulation?
Responda
  • 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.

Questão 39

Questão
An object is an instance of a ________.
Responda
  • program
  • class
  • method
  • data

Questão 40

Questão
Assume s is " abc ", the method ________ returns a new string "abc".
Responda
  • s.trim(s)
  • trim(s)
  • String.trim(s)
  • s.trim()

Questão 41

Questão
Which of the following statements are true about an immutable object?
Responda
  • 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.

Questão 42

Questão
Variables that are shared by every instances of a class are ________.
Responda
  • class variables
  • public variables
  • private variables
  • instance variables

Questão 43

Questão
To get a string from the StringBuffer, you use the toString method.
Responda
  • True
  • False

Questão 44

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

Questão 45

Questão
A static data field can be accessed from any method in the same class.
Responda
  • True
  • False

Questão 46

Questão
Analyze the following code:
Responda
  • 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.

Questão 47

Questão
You can declare variables of the same name in a method even though they are in the same block.
Responda
  • True
  • False

Questão 48

Questão
Java uses ________ to reference the current object.
Responda
  • this
  • that
  • thisObject
  • null

Questão 49

Questão
You should add the static keyword in the place of ? in Line ________ in the following code:
Responda
  • in line 4
  • in line 8
  • in both line 4 and line 8
  • none

Questão 50

Questão
To create an instance of BigDecimal for 454.45, use ________.
Responda
  • BigInteger(454.45);
  • new BigInteger(454.45);
  • BigInteger("454.45");
  • new BigDecimal("454.45");

Questão 51

Questão
What is the output of the following code?
Responda
  • s1 and s2 reference to the same String object
  • s1 and s2 reference to different String objects

Questão 52

Questão
Analyze the following code.
Responda
  • 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.

Questão 53

Questão
Which of the following statements are correct?
Responda
  • 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.

Questão 54

Questão
Java assigns a default value to a data member of a class if the data is not initialized.
Responda
  • True
  • False

Questão 55

Questão
Analyze the following code:
Responda
  • 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").

Questão 56

Questão
Which of the following statements are true?
Responda
  • 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.

Questão 57

Questão
Which of the following statements is preferred to create a string "Welcome to Java"?
Responda
  • 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");

Questão 58

Questão
A static data field can be accessed from any method in the same class.
Responda
  • True
  • False

Questão 59

Questão
What code may be filled in the blank without causing syntax or runtime errors?
Responda
  • test.date
  • date
  • test.date.toString()
  • date.toString()

Questão 60

Questão
What is displayed by the following code?
Responda
  • A,B;C;D
  • A B C D
  • A B C;D
  • A B;C;D

Questão 61

Questão
To add BigInteger b1 to b2, you write ________.
Responda
  • b1.add(b2);
  • b2.add(b1);
  • b2 = b1.add(b2);
  • b2 = b2.add(b1);
  • b1 = b2.add(b1);

Questão 62

Questão
Assume s is "ABCABC", the method ________ returns a new string "aBCaBC".
Responda
  • s.toLowerCase(s)
  • s.toLowerCase()
  • s.replace('A', 'a')
  • s.replace('a', 'A')
  • s.replace("ABCABC", "aBCaBC")

Questão 63

Questão
You can declare variables of the same name in a method if they are in non-nesting blocks.
Responda
  • True
  • False

Questão 64

Questão
Analyze the following code.
Responda
  • 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.

Questão 65

Questão
What is the output of the following code?
Responda
  • 3
  • 4
  • 10
  • 11

Questão 66

Questão
An immutable class cannot have ________.
Responda
  • public data fields
  • private data fields
  • public constructors
  • no-arg constructors
  • static data fields

Questão 67

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

Questão 68

Questão
Assume StringBuilder strBuf is "ABCDEFG", after invoking ________, strBuf contains "ABCRRRRDEFG".
Responda
  • strBuf.insert(1, "RRRR")
  • strBuf.insert(2, "RRRR")
  • strBuf.insert(3, "RRRR")
  • strBuf.insert(4, "RRRR")

Questão 69

Questão
Given the declaration Circle x = new Circle(), which of the following statement is most accurate?
Responda
  • 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.

Questão 70

Questão
Each class in the file is compiled into a separate bytecode file.
Responda
  • True
  • False

Questão 71

Questão
Which of the following statements are true?
Responda
  • 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.

Semelhante

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