Quiz
Java Practice 3
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (105)
1Which class do you use to write data into a text file?
- ASystem
- BPrintWriter
- CScanner
- DFile
2Which of the following statements is false?
- AThe smallest data item a computer can assume is the value 0 or the value 1.
- BThe term "bit" is short for "byte digit."
- CJava uses the Unicode character set.
- DA record is typically composed of several fields.
3What is the return value of "SELECT".substring(0, 5)?
- A"SELECT"
- B"SELE"
- C"SELEC"
- D"ELECT"
4Which of the following assignment statements is incorrect? (Choose all that apply.)
- Ai == j == k == 1;
- Bi = j = k = 1;
- Ci = 1; j = 1; k = 1;
- Di = 1 = j = 1 = k = 1;
5An argument type followed by a(n) __________________ in a method's parameter list indicates that the method receives a variable number of arguments of that particular type.
- Asquare brackets ([]).
- Bellipsis ().
- Cvarargs keyword.
- DAll of the above are acceptable to indicate a variable number of arguments.
6Which of the following statements creates a multidimensional array with 3 rows, where the first row contains 1 element, the second row contains 4 elements and the final row contains 2 elements?
- Aint[][] items = { { 1, null, null, null }, { 2, 3, 4, 5 }, { 6, 7, null, null } };.
- Bint[][] items = { { 1 }, { 2, 3, 4, 5 }, { 6, 7 } };.
- Cint[][] items = { { 1 }, { 2, 3, 4, 5 }, { 6, 7 }, {} );.
- Dint[][] items = { { 1 }, { 4 }, { 2 } };.
7What 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?
- Aprotected
- Bpublic
- Cprivate
- DUse the default modifier.
8Which of the following statements are true about an immutable object? (Choose all that apply.)
- AThe contents of an immutable object cannot be modified.
- BAn immutable object contains no mutator methods.
- CAll properties of an immutable object must be of primitive types.
- DAll properties of an immutable object must be private.
- EAn object type property in an immutable object must also be immutable.
9What 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;
s1 += "and Welcome to HTML";
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");
}
}- As1 and s2 reference to different String objects
- Bs1 and s2 reference to the same String object
10Which of the following is not an algorithm?
- AA recipe.
- BOperating instructions.
- CTextbook index.
- DShampoo instructions (lather, rinse, repeat).
11Which of the following segments is a proper way to call the method readData four times?
- Adouble k;
k = 0.0;
while (k != 4) {
readData();
k = k + 1;
} // end while - Bint i;
i = 0;
while ( i <= 4 ) {
readData();
i = i + 1;
} // end while - Cint i;
i = 0;
while ( i < 4 ) {
readData();
} // end while - Dint i;
i = 0;
while ( i < 4 ) {
readData();
i = i + 1;
} // end while
- Adouble k;
12Which method returns an array of the enum’s constants?
- Avalues.
- BgetValues.
- Cconstants.
- DgetConstants.
13An anonymous String:
- Ahas no value.
- Bis a string literal.
- Ccan be changed.
- Dnone of the above.
14What exception type does the following program throw?
public class Test {
public static void main(String[ ] args) {
Object o = null;
System.out.println(o);
}
}- AStringIndexOutOfBoundsException
- BNullPointerException
- CArrayIndexOutOfBoundsException
- DNo exception
- EArithmeticException
15Overloaded methods always have the same _________.
- Amethod name.
- Breturn type.
- Cnumber of parameters.
- Dorder of the parameters.
16All import declarations must be placed
- Ainside the class declaration’s body.
- Bbefore the class declaration.
- Cafter the class declaration.
- Dall of the above will work.
17The preferred way to traverse a two-dimensional array is to use _______ .
- Aa do while statement.
- Ba for statement.
- Ctwo nested for statements.
- Dthree nested for statements.
18Which of the following will count down from 10 to 1 correctly?
- Afor ( int j = 10; j <= 1; j++ )
- Bfor ( int j = 1; j <= 10; j++ )
- Cfor ( int j = 10; j > 1; j-- )
- Dfor ( int j = 10; j >= 1; j-- )
19Which of the following does not contribute to improved software reusability?
- AQuickly creating new class libraries without testing them thoroughly.
- BLicensing schemes and protection mechanisms.
- CDescriptions of classes that allow programmers to determine whether a class fits their needs.
- DCataloging schemes and browsing mechanisms.
20What code may be filled in the blank without causing syntax or runtime errors:
public class Test {
java.util.Date date;
public static void main(String[ ] args) {
Test test = new Test();
System.out.println(________);
}
}- Adate
- Btest.date
- Cdate.toString()
- Dtest.date.toString()
21Which of the following is a valid identifier? (Choose all that apply.)
- Aclass
- Bradius
- C9X
- D8+9
- E$343
22When should a program explicitly use the this reference?
- AAccessing a private variable.
- BAccessing a public variable.
- CAccessing a local variable.
- DAccessing a field that is shadowed by a local variable.
23Variables that are shared by every instances of a class are ________.
- Aclass variables
- Bpublic variables
- Cprivate variables
- Dinstance variables
24Which of the following is true? (Choose all that apply.)
- AThe capacity of a string buffer can be automatically adjusted.
- BYou can reverse the characters in a string buffer.
- CYou can add characters into a string buffer.
- DYou can delete characters into a string buffer.
25Which of the following is arranged in increasing size order?
- Afield, bit, file, record.
- Bbyte, file, database, record.
- Cbyte, field, file, record.
- Dbit, field, record, file.
26Which method can be used to read a whole line from the file?
- AnextInt
- Bnext
- CnextLine
- DnextDouble
27-24 % -5 is ________.
- A3
- B-3
- C4
- D-4
- E0
28Analyze the following code.
public class Test {
public static void main(String[ ] args) {
int month = 09;
System.out.println("month is " + month);
}
}- AThe program displays month is 9.0
- BThe program displays month is 9
- CThe program displays month is 09
- DThe program has a syntax error, because 09 is an incorrect literal value.
29A decision symbol in an activity diagram takes the shape of a ________.
- ADiamond.
- BRectangle.
- CCircle.
- DTriangle.
30Analyze the following code.
// Program 1:
public class Test {
public static void main(String[ ] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(a1.equals(a2));
}
}
class A {
int x;
public boolean equals(Object a) {
return this.x == ((A)a)x;
}
}
// Program 2:
public class Test {
public static void main(String[ ] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(a1.equals(a2));
}
}
class A {
int x;
public boolean equals(A a) {
return this.x == a.x;
}
}- AProgram 1 displays true and Program 2 displays true
- BProgram 1 displays true and Program 2 displays false
- CProgram 1 displays false and Program 2 displays true
- DProgram 1 displays false and Program 2 displays false
31Which correctly creates an array of five empty Strings?
- AString[ ] a = new String [5];
- BString[ ] a = new String [5]; for (int i = 0; i < 5; a[i++] = null);
- CString[ ] a = {"", "", "", "", ""};
- DString[5] a;
32Which of the following are Java keywords?
- Ainstanceof
- BinstanceOf
- Ccasting
- Dcast
33When you return an array from a method, the method returns ________.
- Aa copy of the array
- Bthe reference of the array
- Ca copy of the first element
- Dthe length of the array
34What 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");
}
}- As1 and s2 reference to different String objects
- Bs1 and s2 reference to the same String object
35Which of the following should usually be private?
- AMethods.
- BConstructors.
- CVariables (or fields).
- DAll of the above.
36When an argument is passed by reference:
- Aa copy of the argument’s value is passed to the called method.
- Bchanges to the argument do not affect the original variable’s value in the caller.
- Cthe called method can access the argument’s value in the caller directly and modify that data.
- Dthe original value is removed from memory.
37How many times will the following code print "Welcome to Java"?
int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 10);- A10
- B8
- C0
- D9
- E11
38Suppose TestCircle and Circle in Listing 7.1 in the textbook are in two separate files named TestCircle.java and Circle.java, respectively. What is the outcome of compiling TestCircle.java and then Circle.java?
- AOnly TestCircle.java compiles.
- BBoth compile fine.
- CNeither compiles successfully.
- DOnly Circle.java compiles.
39The default value for data field of a boolean type, numeric type, object type is ________, respectively.
- Atrue, 1, Null
- Btrue, 1, null
- Cfalse, 0, null
- Dfalse, 1, null
- Etrue, 0, null
40Which of the following is not a valid Java identifier?
- Amy Value
- B$_AAA1
- Cwidth
- Dm_x
41Consider the array:
s[ 0 ] = 7
s[ 1 ] = 0
s[ 2 ] = -12
s[ 3 ] = 9
s[ 4 ] = 10
s[ 5 ] = 3
s[ 6 ] = 6
The value of s[ s[ 6 ] - s[ 5 ] ] is- A0
- B3
- C9
42Which of the following is not a superclass/subclass relationship?
- AFord/Taurus.
- BUniversity/Brown University.
- CSailboat/Tugboat.
- DCountry/USA.
43Which of the following is the shape of an action-state symbol?
- ADiamond.
- BCircle.
- CRectangle with left and right sides replaced with arcs curving outward.
- DRounded rectangle.
44Analyze the following code:
public class Test1 {
public static void main(String[ ] args) {
xMethod(new double[ ]{3, 3});
xMethod(new double[5]);
xMethod(new double[3]{1, 2, 3});
}
public static void xMethod(double[ ] a) {
System.out.println(a.length);
}
}- AThe program has a compile error because xMethod(new double[ ]{3, 3}) is incorrect.
- BThe program has a compile error because xMethod(new double[3]{1, 2, 3}) is incorrect.
- CThe program has a compile error because xMethod(new double[5]) is incorrect.
- DThe program has a runtime error because a is null.
45What is output by the following Java code segment?
int temp;
temp = 180;
if ( temp > 90 )
{
System.out.println( "This porridge is too hot." );
// cool down
temp = temp – ( temp > 150 ? 100 : 20 );
} // end if
else
{
if ( temp < 70 )
{
System.out.println("This porridge is too cold.");
// warm up
temp = temp + (temp < 50 ? 30 : 20);
} // end if
} // end else
if ( temp == 80 )
System.out.println( "This porridge is just right!" );
- AThis porridge is too hot.
- BThis porridge is too cold. This porridge is just right!
- CThis porridge is just right!
- DNone of the above.
46A method must declare to throw ________.
- AError
- Bunchecked exceptions
- Cchecked exceptions
- DRuntimeException
47What is displayed on the console when running the following program?
class Test {
public static void main(String[ ] args) {
try {
System.out.println("Welcome to Java");
int i = 0;
int y = 2/i;
System.out.println("Welcome to Java");
}
catch (RuntimeException ex) {
System.out.println("Welcome to Java");
}
finally {
System.out.println("End of the block");
}
System.out.println("End of the block");
}
}- AThe program displays Welcome to Java three times followed by End of the block.
- BThe program displays Welcome to Java two times followed by End of the block two times.
- CThe program displays Welcome to Java two times followed by End of the block.
- DYou cannot catch RuntimeException errors.
48Which syntax imports all static members of class Math?
- Astatic import java.lang.Math.*.
- Bimport static java.lang.Math.*.
- Cstatic import java.lang.Math.
- Dimport static java.lang.Math.
49The StringBuilder methods ________ not only change the contents of a string buffer, but also returns a reference to the string buffer. (Choose all that apply.)
- Adelete
- Breplace
- Cappend
- Dreverse
- Einsert
50Every letter in a Java keyword is in lowercase.
- Atrue
- Bfalse
51Math.pow(2, 3) returns ________.
- A8.0
- B9.0
- C8
- D9
52Which of the following classes cannot be extended?
- Aclass A { protected A();}
- Bclass A { private A();}
- Cfinal class A { }
- Dclass A { }
53In an expression containing values of the types int and double, the ________ values are ________ to ________ values for use in the expression.
- Aint, promoted, double.
- Bint, demoted, double.
- Cdouble, promoted, int.
- Ddouble, demoted, int.
54Having a this reference allows:
- Aa method to refer explicitly to the instance variables and other methods of the object on which the method was called.
- Ba method to refer implicitly to the instance variables and other methods of the object on which the method was called.
- Can object to reference itself.
- DAll of the above.
55An instance of ________ describes programming errors, such as bad casting, accessing an out-of-bounds array, and numeric errors..
- AException
- BNumberFormatException
- CError
- DRuntimeException
- EThrowable
56Analyze the following code.
// Program 1
public class Test {
public static void main(String[ ] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(((A)a1).equals((A)a2));
}
}
class A {
int x;
public boolean equals(A a) {
return this.x == a.x;
}
}
// Program 2
public class Test {
public static void main(String[ ] args) {
A a1 = new A();
A a2 = new A();
System.out.println(a1.equals(a2));
}
}
class A {
int x;
public boolean equals(A a) {
return this.x == a.x;
}
}- AProgram 1 displays false and Program 2 displays false
- BProgram 1 displays true and Program 2 displays true
- CProgram 1 displays true and Program 2 displays false
- DProgram 1 displays false and Program 2 displays true
57How many significant digits does a double variable have?
- A7.
- B8.
- C14.
- D15.
58In Java graphics, coordinate units are measured in ________.
- Adots.
- Bpixels.
- Cpoints.
- Dinches.
59Which code fragment would correctly identify the number of arguments passed via the command line to a Java application, excluding the name of the class that is being invoked?
- Aint count = 0; while (args[count] != null) count ++;
- Bint count = args.length;
- Cint count = args.length - 1;
- Dint count=0; while (!(args[count].equals(""))) count ++;
60The ________ method returns a raised to the power of b.
- AMath.pow(a, b)
- BMath.pow(b, a)
- CMath.power(a, b)
- DMath.exponent(a, b)
61Which of the following will not produce a compiler error?
- AChanging the value of a constant after it is declared.
- BChanging the value at a given index of an array after it is created.
- CUsing a final variable before it is initialized.
- DAll of the above will produce compiler errors.
62The default equals implementation determines:
- Awhether two references refer to the same object in memory.
- Bwhether two references have the same type.
- Cwhether two objects have the same instance variables.
- Dwhether two objects have the same instance variable values.
63Analyze the following code:
public class Test {
public static void main(String[ ] args) {
B b = new B();
b.m(5);
System.out.println("i is " + b.i);
}
}
class A {
int i;
public void m(int i) {
this.i = i;
}
}
class B extends A {
public void m(String s) {
}
}- AThe program has a compilation error, because m is overridden with a different signature in B.
- BThe method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.
- CThe program has a runtime error on b.i, because i is not accessible from b.
- DThe program has a compilation error, because b.m(5) cannot be invoked since the method m(int) is hidden in B.
64What is the output of the following program?
import java.util.Date;
public class Test {
public static void main(String[ ] args) {
Date date = new Date(1234567);
m1(date);
System.out.print(date.getTime() + " ");
m2(date);
System.out.println(date.getTime());
}
public static void m1(Date date) {
date = new Date(7654321);
}
public static void m2(Date date) {
date.setTime(7654321);
}
}- A7654321 1234567
- B1234567 7654321
- C7654321 7654321
- D1234567 1234567
65Given the following method
static void nPrint(String message, int n) {
while (n > 0) {
System.out.print(message);
n--;
}
}
What is the printout of the call nPrint('a', 4)?- Aaaaa
- Baaa
- Cinvalid call
- Daaaaa
66Which of the following can be used in the expression after keyword case?
A. a constant integral expression.
B. a character constant.
C. a constant.
D. an enumeration constant.- AA and B.
- BA and C.
- CB and C.
- DAll.
67In array items, which expression below accesses the value at row 3 and column 4?
- Aitems[ 3 ].[ 4 ].
- Bitems[ 3[ 4 ] ].
- Citems[ 3 ][ 4 ].
- Ditems[ 3, 4 ].
68Which of the following is the correct statement to return JAVA?
- AString.toUpperCase("Java")
- B"Java".toUpperCase()
- CtoUpperCase("Java")
- D"Java".toUpperCase("Java")
69Which statement is false?
- AThe actual data representation used within the class is of no concern to the class's clients.
- BClients generally care about what the class does but not how the class does it.
- CClients are usually involved in a class's implementation.
- DHiding the implementation reduces the possibility that clients will become dependent on class-implementation details.
70Which of the following is not an arithmetic operator?
- A+
- B-
- C.
- D%
71Which of the following classes is not used for file input?
- AFileInputStream
- BFileReader
- CObjectInputStream
- DFormatter
72Consider the code segment below.
if ( gender == 1 )
{
if ( age >= 65 )
++seniorFemales;
} // end if
This segment is equivalent to which of the following?- Aif ( gender == 1 || age >= 65 )
++seniorFemales; - Bif ( gender == 1 && age >= 65 )
++seniorFemales; - Cif ( gender == 1 AND age >= 65 )
++seniorFemales; - Dif ( gender == 1 OR age >= 65 )
++seniorFemales;
- Aif ( gender == 1 || age >= 65 )
73A final field should also be declared ________ if it is initialized in its declaration.
- Aprivate.
- Bpublic.
- Cprotected.
- Dstatic.
74The ________ method displays an input dialog for reading a string. (Choose all that apply.)
- AString string = JOptionPane.showInputDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE);
- BString string = JOptionPane.showInputDialog(null, "Enter a string");
- CString string = JOptionPane.showInputDialog("Enter a string");
- DString string = JOptionPane.showInputDialog("Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE);
- EString string = JOptionPane.showMessageDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE);
75A default constructor has how many parameters?
- A0.
- B1.
- C2.
- DVariable.
76The ________ method immediately terminates the program.
- ASystem.stop(0);
- BSystem.halt(0);
- CSystem.terminate(0);
- DSystem.exit(0);
- ESystem.quit(0);
77Sentinel-controlled repetition is also known as:
- ADefinite repetition.
- BIndefinite repetition.
- CMultiple repetition.
- DDouble repetition.
78Polymorphism means ________.
- Athat a class can extend another class
- Bthat data fields should be declared private
- Cthat a class can contain another class
- Dthat a variable of supertype can refer to a subtype object
79Which of the following is not a syntax error?
- ASystem.out.println( 'Hello world!' ):
- BSystem.out.println( "Hello . world!" );
- CSystem.out.println( "Hello world!" );
- DSystem.out.println( Hello world! );
80What is k after the following block executes?
{
int k = 2;
nPrint("A message", k);
}
System.out.println(k);- A2
- B1
- C0
- Dk is not defined outside the block. So, the program has a compile error
81The _________ of a class are also called the public services or the public interface that the class provides to its clients.
- Apublic constructors.
- Bpublic instance variables.
- Cpublic methods.
- DAll of the above.
82Analyze the following code: (Choose all that apply.)
public class Test {
public static void main(String[ ] args) {
Object a1 = new A();
Object a2 = new Object();
System.out.println(a1);
System.out.println(a2);
}
}
class A {
int x;
public String toString() {
return "A's x is " + x;
}
}- AWhen executing System.out.println(a1), the toString() method in the Object class is invoked.
- BWhen executing System.out.println(a1), the toString() method in the A class is invoked.
- CWhen executing System.out.println(a2), the toString() method in the Object class is invoked.
- DThe program cannot be compiled, because System.out.println(a1) is wrong and it should be replaced by System.out.println(a1.toString());
83What do the following statements do?
double[] array;
array = new double[ 14 ];- ACreate a double array containing 13 elements.
- BCreate a double array containing 14 elements.
- CCreate a double array containing 15 elements.
- DDeclare but do not create a double array.
84When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as ________.
- Apass by name
- Bpass by value
- Cpass by reference
- Dmethod invocation
85Which of following is not a correct method in Character? (Choose all that apply.)
- AisDigit()
- BtoLowerCase(char)
- CisLetter(char)
- DtoUpperCase()
- EisLetterOrDigit(char)
86Given the following classes and their objects:
class C1 {};
class C2 extends C1 {};
class C3 extends C1 {};
C2 c2 = new C2();
C3 c3 = new C3();
Analyze the following statement:
c2 = (C2)((C1)c3);- AYou will get a runtime error because you cannot cast objects from sibling classes.
- BYou will get a runtime error because the Java runtime system cannot perform multiple casting in nested form.
- Cc3 is cast into c2 successfully.
- DThe statement is correct.
87Every class in Java, except ________, extends an existing class.
- AInteger.
- BObject.
- CString.
- DClass.
88By default, the classpath consists only of the ________. However, the classpath can be modified by providing the ________ option to the javac compiler.
- Aroot directory of the package, -d.
- Bcurrent directory, -d.
- Croot directory of the package, -classpath.
- Dcurrent directory, -classpath.
89Which of the following is not a compilation error?
- ANeglecting to initialize a local variable in a method before it is used.
- BPlacing a semicolon at the end of the first line of an if statement.
- COmitting the left and right parenthesis for the condition of an if statement.
- DAll are compilation errors.
90________ is a simple but incomplete version of a method.
- AA non-main method
- BA method developed using top-down approach
- CA stub
- DA main method
91What is displayed by the following code?
public static void main(String[ ] args) throws Exception {
String[ ] tokens = "Welcome to Java".split("o");
for (int i = 0; i < tokens.length; i++) {
System.out.print(tokens[i] + " ");
}
}- AWelcome t Java
- BWelc me t Java
- CWelc me to Java
- DWelcome to Java
92Which of the following code segments does not increment val by 3:
- Aval += 3;
- Bval = val+1;
val = val+1;
val = val+1; - Cc = 3;
val = val + (c == 3 ? 2 : 3); - DAll of the above increment val by 3.
93The import declaration import *; ________.
- Acauses a compilation error.
- Bimports all classes in the library.
- Cimports the default classes in the library.
- Dimports the classes in package java.lang.
94An 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.
- ARuntimeException
- BThrowable
- CError
- DException
- ENumberFormatException
95An instance of ________ describes the errors caused by your program and external circumstances. These errors can be caught and handled by your program.
- ANumberFormatException
- BError
- CRuntimeException
- DThrowable
- EException
96What is the value of result after the following Java statements execute?
int a, b, c, d, result;
a = 4;
b = 12;
c = 37;
d = 51;
result = d % a * c + a % b + a;- A119
- B51
- C127
- D59
97When method printf requires multiple arguments, the arguments are separated with ________.
- Acolons (:).
- Bsemicolons (;).
- Ccommas (,).
- Dperiods (.).
98Analyze the following statement:
double sum = 0;
for (double d = 0; d<10;) {
d += 0.1;
sum += sum + d;
}- AThe program compiles and runs fine.
- BThe program runs in an infinite loop because d<10 would always be true.
- CThe program has a compile error because the control variable in the for loop cannot be of the double type.
- DThe program has a compile error because the adjustment is missing in the for loop.
99Suppose x is 1. What is x after x -= 1?
- A0
- B1
- C2
- D-1
- E-2
100Stacks are known as ________ data structures.
- AFIFO.
- BFILO.
- CLIFO.
- DLILO.
101Which statement is true when a superclass has protected instance variables?
- AA subclass object can assign an invalid value to the superclass’s instance variables, thus leaving an object in an inconsistent state.
- BSubclass methods are more likely to be written so that they depend on the superclass’s data implementation.
- CWe may need to modify all the subclasses of the superclass if the superclass implementation changes.
- DAll of the above.
102If you enter 1 2 3, when you run this program, what will be the output?
import java.util.Scanner;
public class Test1 {
public static void main(String[ ] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three numbers: ");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();
// Compute average
double average = (number1 + number2 + number3) / 3;
// Display result
System.out.println(average);
}
}- A1.0
- B2.0
- C4.0
- D3.0
103Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following methods will cause the list to become [Beijing, Chicago, Singapore]?
- Ax.add(2, "Chicago")
- Bx.add(1, "Chicago")
- Cx.add("Chicago")
- Dx.add(0, "Chicago")
104Which of the following statements are true?
- AIf a file (e.g., c:\temp.txt) does not exist, new File("c:\\temp.txt") creates a new file named c:\temp.txt.
- BIf a directory (e.g., c:\liang) does not exist, new File("c:\liang") creates a new directory named c:\liang.
- CIf a directory (e.g., c:\liang) does not exist, new File("c:\liang") returns null.
- DIf a file (e.g., c:\temp.txt) does not exist, new File("c:\\temp.txt") returns null.
- ENone of the above.
105The visibility of these modifiers increases in this order:
- Anone (if no modifier is used), private, protected, and public.
- Bnone (if no modifier is used), protected, private, and public.
- Cprivate, protected, none (if no modifier is used), and public.
- Dprivate, none (if no modifier is used), protected, and public.
Information
- Description
- A practice test for Java level 1 at Gwinnett Technical College
- Author
- Ummm No
- Language
- English
- Views
- 321
- Tags
- Rating
- No ratings yet Rate this quiz