chapters 9 and 10 pt 1

Descripción

chapters 9 and 10
Joe Delisle
Test por Joe Delisle, actualizado hace más de 1 año
Joe Delisle
Creado por Joe Delisle hace casi 7 años
222
0

Resumen del Recurso

Pregunta 1

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

Pregunta 2

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

Pregunta 3

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

Pregunta 4

Pregunta
Analyze the following code.
Respuesta
  • 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.

Pregunta 5

Pregunta
The following program displays ________.
Respuesta
  • Java
  • Java and HTML
  • and HTML
  • nothing is displayed

Pregunta 6

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

Pregunta 7

Pregunta
Which of the following statements are true?
Respuesta
  • 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.

Pregunta 8

Pregunta
What is the output of the following program?
Respuesta
  • 1234567 1234567
  • 1234567 7654321
  • 7654321 1234567
  • 7654321 7654321

Pregunta 9

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

Pregunta 10

Pregunta
BigInteger and BigDecimal are immutable
Respuesta
  • True
  • False

Pregunta 11

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

Pregunta 12

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

Pregunta 13

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

Pregunta 14

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

Pregunta 15

Pregunta
Which of the following is true?
Respuesta
  • 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.

Pregunta 16

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

Pregunta 17

Pregunta
You can create an instance of the Math class.
Respuesta
  • True
  • False

Pregunta 18

Pregunta
Which of the following can be placed in the blank line in the following code?
Respuesta
  • this
  • Test

Pregunta 19

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

Pregunta 20

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

Pregunta 21

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

Pregunta 22

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

Pregunta 23

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

Pregunta 24

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

Pregunta 25

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

Pregunta 26

Pregunta
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?
Respuesta
  • Only TestCircle1.java compiles.
  • Only Circle1.java compiles.
  • Both compile fine.
  • Neither compiles successfully.

Pregunta 27

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

Pregunta 28

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

Pregunta 29

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

Pregunta 30

Pregunta
All local variables in a method have default values.
Respuesta
  • True
  • False

Pregunta 31

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

Pregunta 32

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

Pregunta 33

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

Pregunta 34

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

Pregunta 35

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

Pregunta 36

Pregunta
All local variables in a method have default values.
Respuesta
  • True
  • False

Pregunta 37

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

Pregunta 38

Pregunta
Which is the advantage of encapsulation?
Respuesta
  • 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.

Pregunta 39

Pregunta
An object is an instance of a ________.
Respuesta
  • program
  • class
  • method
  • data

Pregunta 40

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

Pregunta 41

Pregunta
Which of the following statements are true about an immutable object?
Respuesta
  • 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.

Pregunta 42

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

Pregunta 43

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

Pregunta 44

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

Pregunta 45

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

Pregunta 46

Pregunta
Analyze the following code:
Respuesta
  • 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.

Pregunta 47

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

Pregunta 48

Pregunta
Java uses ________ to reference the current object.
Respuesta
  • this
  • that
  • thisObject
  • null

Pregunta 49

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

Pregunta 50

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

Pregunta 51

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

Pregunta 52

Pregunta
Analyze the following code.
Respuesta
  • 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.

Pregunta 53

Pregunta
Which of the following statements are correct?
Respuesta
  • 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.

Pregunta 54

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

Pregunta 55

Pregunta
Analyze the following code:
Respuesta
  • 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").

Pregunta 56

Pregunta
Which of the following statements are true?
Respuesta
  • 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.

Pregunta 57

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

Pregunta 58

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

Pregunta 59

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

Pregunta 60

Pregunta
What is displayed by the following code?
Respuesta
  • A,B;C;D
  • A B C D
  • A B C;D
  • A B;C;D

Pregunta 61

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

Pregunta 62

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

Pregunta 63

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

Pregunta 64

Pregunta
Analyze the following code.
Respuesta
  • 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.

Pregunta 65

Pregunta
What is the output of the following code?
Respuesta
  • 3
  • 4
  • 10
  • 11

Pregunta 66

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

Pregunta 67

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

Pregunta 68

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

Pregunta 69

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

Pregunta 70

Pregunta
Each class in the file is compiled into a separate bytecode file.
Respuesta
  • True
  • False

Pregunta 71

Pregunta
Which of the following statements are true?
Respuesta
  • 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.
Mostrar resumen completo Ocultar resumen completo

Similar

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