Escolar Documentos
Profissional Documentos
Cultura Documentos
prompt
in which package can the swing components be found:
type
single
option
com.sun.java.swing.*
option
java.awt.swing.*
option
javax.swing.*
option
java.swing.*
answer
3
explain
swing was placed in the javax standard language extension with the <b>final</b>
release of the java 2 platform.
q
prompt
what is the correct ordering for the import, class and package declarations when
found in a single file?
type
single
option
package, import, class
option
class, import, package
option
import, package, class
option
package, class, import
answer
1
explain
this is my explanation for question 2
endexplain
q
prompt
which methods can be legally applied to a string object?
type
multiple
option
equals(string)
option
equals(object)
option
trim()
option
round()
option
tostring()
answer
1
answer
2
answer
3
answer
5
q
prompt
what is the parameter specification for the public static void main method?
type
multiple
option
string args []
option
string [] args
option
strings args []
option
string args
answer
1
answer
2
q
prompt
what does the zeroth element of the string array passed to the public static void
main method contain?
type
multiple
option
the name of the program
option
the number of arguments
option
the first argument if one is present
answer
3
q
prompt
which of the following are java keywords?
type
multiple
option
goto
option
malloc
option
extends
option
false
option
sizeof
option
friend
answer
3
q
prompt
what will be the result of compiling the following code:
code
public class test {
public static void main (string args []) {
int age;
age = age + 1;
system.out.println("the age is " + age);
}
}
endcode
type
single
option
compiles and runs with no output
option
compiles and runs printing out the age is 1
option
compiles but generates a runtime error
option
does not compile
option
compiles but generates a compile time error
answer
4
q
prompt
which of these is the correct format to use to create the literal char value a?
type
multiple
option
'a'
option
"a"
option
new character(a)
option
\000a
answer
1
q
prompt
what is the legal range of a byte integral type?
type
single
option
0 - 65, 535
option
(-128) - 127
option
(-32,768) - 32,767
option
(-256) - 255
answer
2
q
prompt
which of the following is illegal:
type
single
option
int i = 32;
option
float f = 45.0;
option
double d = 45.0;
option
string a = 32;
answer
2
q
prompt
what will be the result of compiling the following code:
code
public class test {
static int age;
public static void main (string args []) {
age = age + 1;
system.out.println("the age is " + age);
}
}
endcode
type
single
option
compiles and runs with no output
option
compiles and runs printing out the age is 1
option
compiles but generates a runtime error
option
does not compile
option
compiles but generates a compile time error
answer
2
q
prompt
which of the following are correct?
type
multiple
option
128 >> 1 gives 64
option
128 >>> 1 gives 64
option
128 >> 1 gives -64
option
128 >>> 1 gives -64
answer
1
q
prompt
which of the following return true?
type
multiple
option
"john" == new string("john")
option
"john".equals("john")
option
"john" = "john"
option
"john".equals(new button("john"))
answer
2
q
prompt
which of the following do not lead to a runtime error?
type
multiple
option
"john" + " was " + " here"
option
"john" + 3
option
3 + 5
option
5 + 5.5
answer
1
answer
2
answer
3
answer
4
q
prompt
which of the following are so called "short circuit" logical operators?
type
multiple
option
&
option
||
option
&&
option
|
answer
2
answer
3
q
prompt
which of the following are acceptable?
type
multiple
option
object o = new button("a");
option
boolean flag = true;
option
panel p = new frame();
option
frame f = new panel();
option
panel p = new applet();
answer
1
answer
5
q
prompt
what is the result of compiling and running the following code:
code
public class test {
static int total = 10;
public static void main (string args []) {
new test();
}
public test () {
system.out.println("in test");
system.out.println(this);
int temp = this.total;
if (temp > 5) {
system.out.println(temp);
}
}
}
endcode
type
multiple
option
the class will not compile
option
the compiler reports and error at line 2
option
the compiler reports an error at line 9
option
the value 10 is one of the elements printed to the standard output
option
the class compiles but generates a runtime error
answer
4
q
prompt
which of the following is correct:
type
single
option
string temp [] = new string {"j" "a" "z"};
option
string temp [] = { "j " " b" "c"};
option
string temp = {"a", "b", "c"};
option
string temp [] = {"a", "b", "c"};
answer
4
q
prompt
what is the correct declaration of an abstract method that is intended to be
public:
type
single
option
public abstract void add();
option
public abstract void add() {}
option
public abstract add();
option
public virtual add();
answer
1
q
prompt
under what situations do you obtain a default constructor?
type
single
option
when you define any class
option
when the class has no other constructors
option
when you define at least one constructor
answer
2
q
prompt
which of the following can be used to define a constructor for this class, given
the following code:
code
public class test {
...
}
endcode
type
single
option
public void test() {...}
option
public test() {...}
option
public static test() {...}
option
public static void test() {...}
answer
2
q
prompt
which of the following are acceptable to the java compiler:
type
multiple
option
if (2 == 3) system.out.println("hi");
option
if (2 = 3) system.out.println("hi");
option
if (true) system.out.println("hi");
option
if (2 != 3) system.out.println("hi");
option
if (astring.equals("hello")) system.out.println("hi");
answer
1
answer
3
answer
4
answer
5
q
prompt
assuming a method contains code which may raise an exception (but not a
runtimeexception), what is the correct way for a method to indicate that it
expects the caller to handle that exception:
type
single
option
throw exception
option
throws exception
option
new exception
option
don't need to specify anything
answer
2
q
prompt
what is the result of executing the following code, using the parameters 4 and 0:
code
public void divide(int a, int b) {
try {
int c = a / b;
} catch (exception e) {
system.out.print("exception ");
} finally {
system.out.println("finally");
}
endcode
type
singe
option
prints out: exception finally
option
prints out: finally
option
prints out: exception
option
no output
answer
1
q
prompt
which of the following is a legal return type of a method overloading the
following method:
code
endcode
type
single
option
the overriding method must return void
option
the overriding method must return int
option
the overriding method can return whatever it likes
answer
1
q
prompt
given the following classes defined in separate files, what will be the effect of
compiling and running this class test?
code
class vehicle {
public void drive() {
system.out.println("vehicle: drive");
}
}
new arraylist(5);
endcode
type
single
option
an indexoutofbounds exception is raised.
option
the arraylist grows to accomodate the sixth element
option
the new element will be lost
option
nothing, the arraylist will have grown when the fifth element was added
answer
2
q
prompt
which of the following defines an interface which acts as the root of all
collection classes (except maps)?
type
single
option
collections
option
collection
option
list
option
arrays
option
array
answer
2
q
prompt
which of the following defines an interface that allows a key to be associated
with a value:
type
single
option
map
option
set
option
list
option
collection
option
enumeration
answer
1
q
prompt
what is the result of executing the following code when the value of x is 2:
code
switch (x) {
case 1:
system.out.println(1);
case 2:
case 3:
system.out.println(3);
case 4:
system.out.println(4);
}
endcode
type
single
option
nothing is printed out
option
the value 3 is printed out
option
the values 3 and 4 are printed out
option
the values 1, 3 and 4 are printed out
answer
3
q
prompt
consider the following example:
code
class first {
public first (string s) {
system.out.println(s);
}
}
public class second extends first {
public static void main(string args []) {
new second();
}
}
endcode
type
single
what is the result of compiling and running the second class?
option
nothing happens
option
a string is printed to the standard out
option
an instance of the class first is generated
option
an instance of the class second is created
option
an exception is raised at runtime stating that there is no null parameter
constructor in class first.
option
the class second will not compile as there is no null parameter constructor in the
class first
answer
6
q
prompt
what is the result of executing the following fragment of code:
code
boolean flag = false;
if (flag = true) {
system.out.println("true");
} else {
system.out.println("false");
}
endcode
type
single
option
true is printed to standard out
option
false is printed to standard out
option
an exception is raised
option
nothing happens
answer
1
q
prompt
consider the following classes. what is the result of compiling and running this
class?
code
public class test {
public static void test() {
this.print();
}
public static void print() {
system.out.println("test");
}
public static void main(string args []) {
test();
}
}
endcode
type
multiple
option
the string test is printed to the standard out.
option
a runtime exception is raised stating that an object has not been created.
option
nothing is printed to the standard output.
option
an exception is raised stating that the method test cannot be found.
option
an exception is raised stating that the variable this can only be used within an
instance.
option
the class fails to compile stating that the variable this is undefined.
answer
6
q
prompt
examine the following class definition:
code
public class test {
public static void test() {
print();
}
public static void print() {
system.out.println("test");
}
public void print() {
system.out.println("another test");
}
}
endcode
type
single
what is the result of compiling this class:
option
a successful compilation.
option
a warning stating that the class has no main method.
option
an error stating that there is a duplicated method.
option
an error stating that the method test() will call one or other of the print()
methods.
answer
3
q
prompt
what is the result of compiling and executing the following java class:
code
public class threadtest extends thread {
public void run() {
system.out.println("in run");
suspend();
resume();
system.out.println("leaving run");
}
public static void main(string args []) {
(new threadtest()).start();
}
}
endcode
type
single
option
compilation will fail in the method main.
option
compilation will fail in the method run.
option
a warning will be generated for method run.
option
the string "in run" will be printed to standard out.
option
both strings will be printed to standard out.
option
nothing will happen.
answer
4
q
prompt
given the following sequence of java statements, which of the following options
are true:
code
1. stringbuffer sb = new stringbuffer("abc");
2. string s = new string("abc");
3. sb.append("def");
4. s.append("def");
5. sb.insert(1, "zzz");
6. s.concat(sb);
7. s.trim();
endcode
type
multiple
option
the compiler would generate an error for line 1.
option
the compiler would generate an error for line 2.
option
the compiler would generate an error for line 3.
option
the compiler would generate an error for line 4.
option
the compiler would generate an error for line 5.
option
the compiler would generate an error for line 6.
option
the compiler would generate an error for line 7.
answer
4
answer
6
q
prompt
what is the result of executing the following java class:
code
import java.awt.*;
<html>
<title>sample applet</title>
<body>
<applet code="sample.class" width=200 height=200></applet>
</body>
</html>
endcode
type
single
option
prints "hello world".
option
generates a runtime error.
option
does nothing.
option
generates a compile time error.
answer
2
q
prompt
what is the effect of compiling and (if possible) running this class:
code
public class calc {
public static void main (string args []) {
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, --j) {
system.out.println(" i = " + i + " : j = " + j);
total += (i + j);
}
system.out.println("total " + total);
}
}
endcode
type
single
option
produce a runtime error
option
produce a compile time error
option
print out "total 0"
option
generate the following as output:
list
i = 0 : j = 10
i = 1 : j = 9
i = 2 : j = 8
total 30
endlist
answer
3
qend
q
prompt
which methods can be legally applied to a string object?
type
multiple
option
equals(string)
option
equals(object)
option
trim()
option
round()
option
tostring()
answer
1
answer
2
answer
3
answer
5
q
prompt
what is the parameter specification for the public static void main method?
type
multiple
option
string args []
option
string [] args
option
strings args []
option
string args
answer
1
answer
2
q
prompt
what does the zeroth element of the string array passed to the public static void
main method contain?
type
multiple
option
the name of the program
option
the number of arguments
option
the first argument if one is present
answer
3
q
prompt
which of the following are java keywords?
type
multiple
option
goto
option
malloc
option
extends
option
false
answer
3
q
prompt
what will be the result of compiling the following code:
code
public class test {
public static void main (string args []) {
int age;
age = age + 1;
system.out.println("the age is " + age);
}
}
endcode
type
single
option
compiles and runs with no output
option
compiles and runs printing out the age is 1
option
compiles but generates a runtime error
option
does not compile
option
compiles but generates a compile time error
answer
4
q
prompt
which of these is the correct format to use to create the literal char value a?
type
multiple
option
'a'
option
"a"
option
new character(a)
option
\000a
answer
1
q
prompt
what is the legal range of a byte integral type?
type
single
option
0 - 65, 535
option
(-128) - 127
option
(-32,768) - 32,767
option
(-256) - 255
answer
2
q
which of the following is illegal:
type
single
option
int i = 32;
option
float f = 45.0;
option
double d = 45.0;
answer
2
q
prompt
what will be the result of compiling the following code:
code
public class test {
static int age;
public static void main (string args []) {
age = age + 1;
system.out.println("the age is " + age);
}
}
endcode
type
single
option
compiles and runs with no output
option
compiles and runs printing out the age is 1
option
compiles but generates a runtime error
option
does not compile
option
compiles but generates a compile time error
answer
2
q
prompt
which of the following are correct?
type
multiple
option
128 >> 1 gives 64
option
128 >>> 1 gives 64
option
128 >> 1 gives -64
option
128 >>> 1 gives -64
answer
1
q
prompt
which of the following return true?
type
multiple
option
"john" == new string("john")
option
"john".equals("john")
option
"john" = "john"
option
"john".equals(new button("john"))
answer
2
q
prompt
which of the following do not lead to a runtime error?
type
multiple
option
"john" + " was " + " here"
option
"john" + 3
option
3 + 5
option
5 + 5.5
answer
1
answer
2
answer
3
answer
4
q
prompt
which of the following are so called "short circuit" logical operators?
type
multiple
option
&
option
||
option
&&
option
|
answer
2
answer
3
q
prompt
which of the following are acceptable?
type
multiple
option
object o = new button("a");
option
boolean flag = true;
option
panel p = new frame();
option
frame f = new panel();
option
panel p = new applet();
answer
1
answer
5
q
prompt
what is the result of compiling and running the following code:
code
public class test {
static int total = 10;
public static void main (string args []) {
new test();
}
public test () {
system.out.println("in test");
system.out.println(this);
int temp = this.total;
if (temp > 5) {
system.out.println(temp);
}
}
}
endcode
type
multiple
option
the class will not compile
option
the compiler reports and error at line 2
option
the compiler reports an error at line 9
option
the value 10 is one of the elements printed to the standard output
option
the class compiles but generates a runtime error
answer
4
q
prompt
which of the following is correct:
type
single
option
string temp [] = new string {"j" "a" "z"};
option
string temp [] = { "j " " b" "c"};
option
string temp = {"a", "b", "c"};
option
string temp [] = {"a", "b", "c"};
answer
4
q
prompt
what is the correct declaration of an abstract method that is intended to be
public:
type
single
option
public abstract void add();
option
public abstract void add() {}
option
public abstract add();
option
public virtual add();
answer
1
q
prompt
under what situations do you obtain a default constructor?
type
single
option
when you define any class
option
when the class has no other constructors
option
when you define at least one constructor
answer
2
q
prompt
which of the following can be used to define a constructor for this class, given
the following code:
code
public class test {
...
}
endcode
type
single
option
public void test() {...}
option
public test() {...}
option
public static test() {...}
option
public static void test() {...}
answer
2
q
prompt
which of the following are acceptable to the java compiler:
type
multiple
option
if (2 == 3) system.out.println("hi");
option
if (2 = 3) system.out.println("hi");
option
if (true) system.out.println("hi");
option
if (2 != 3) system.out.println("hi");
option
if (astring.equals("hello")) system.out.println("hi");
answer
1
answer
3
answer
4
answer
5
q
prompt
assuming a method contains code which may raise an exception (but not a
runtimeexception), what is the correct way for a method to indicate that it
expects the
caller to handle that exception:
type
single
option
bash-3.00$
bash-3.00$
bash-3.00$
bash-3.00$ more questions1.1.txt
q
prompt
which colour is used to indicate instance methods in the standard "javadoc" format
documentation:
type
single
option
blue
option
red
option
purple
option
orange
answer
2
explain
in jdk 1.1 the variabels, methods and constructors are colour coded to
<i>simplify</i> their identification.
endexplain
q
prompt
what is the correct ordering for the import, class and package declarations when
found in a single file?
type
single
option
package, import, class
option
class, import, package
option
import, package, class
option
package, class, import
answer
1
explain
this is my explanation for question 2
endexplain
q
prompt
which methods can be legally applied to a string object?
type
multiple
option
equals(string)
option
equals(object)
option
trim()
option
round()
option
tostring()
answer
1
answer
2
answer
3
answer
5
q
prompt
what is the parameter specification for the public static void main method?
type
multiple
option
string args []
option
string [] args
option
strings args []
option
string args
answer
1
answer
2
q
prompt
what does the zeroth element of the string array passed to the public static void
main method contain?
type
multiple
option
the name of the program
option
the number of arguments
option
the first argument if one is present
answer
3
q
prompt
which of the following are java keywords?
type
multiple
option
goto
option
malloc
option
extends
option
false
answer
3
q
prompt
what will be the result of compiling the following code:
code
public class test {
public static void main (string args []) {
int age;
age = age + 1;
system.out.println("the age is " + age);
}
}
endcode
type
single
option
compiles and runs with no output
option
compiles and runs printing out the age is 1
option
compiles but generates a runtime error
option
does not compile
option
compiles but generates a compile time error
answer
4
q
prompt
which of these is the correct format to use to create the literal char value a?
type
multiple
option
'a'
option
"a"
option
new character(a)
option
\000a
answer
1
q
prompt
what is the legal range of a byte integral type?
type
single
option
0 - 65, 535
option
(-128) - 127
option
(-32,768) - 32,767
option
(-256) - 255
answer
2
q
which of the following is illegal:
type
single
option
int i = 32;
option
float f = 45.0;
option
double d = 45.0;
answer
2
q
prompt
what will be the result of compiling the following code:
code
public class test {
static int age;
public static void main (string args []) {
age = age + 1;
system.out.println("the age is " + age);
}
}
endcode
type
single
option
compiles and runs with no output
option
compiles and runs printing out the age is 1
option
compiles but generates a runtime error
option
does not compile
option
compiles but generates a compile time error
answer
2
q
prompt
which of the following are correct?
type
multiple
option
128 >> 1 gives 64
option
128 >>> 1 gives 64
option
128 >> 1 gives -64
option
128 >>> 1 gives -64
answer
1
q
prompt
which of the following return true?
type
multiple
option
"john" == new string("john")
option
"john".equals("john")
option
"john" = "john"
option
"john".equals(new button("john"))
answer
2
q
prompt
which of the following do not lead to a runtime error?
type
multiple
option
"john" + " was " + " here"
option
"john" + 3
option
3 + 5
option
5 + 5.5
answer
1
answer
2
answer
3
answer
4
q
prompt
which of the following are so called "short circuit" logical operators?
type
multiple
option
&
option
||
option
&&
option
|
answer
2
answer
3
q
prompt
which of the following are acceptable?
type
multiple
option
object o = new button("a");
option
boolean flag = true;
option
panel p = new frame();
option
frame f = new panel();
option
panel p = new applet();
answer
1
answer
5
q
prompt
what is the result of compiling and running the following code:
code
public class test {
static int total = 10;
public static void main (string args []) {
new test();
}
public test () {
system.out.println("in test");
system.out.println(this);
int temp = this.total;
if (temp > 5) {
system.out.println(temp);
}
}
}
endcode
type
multiple
option
the class will not compile
option
the compiler reports and error at line 2
option
the compiler reports an error at line 9
option
the value 10 is one of the elements printed to the standard output
option
the class compiles but generates a runtime error
answer
4
q
prompt
which of the following is correct:
type
single
option
string temp [] = new string {"j" "a" "z"};
option
string temp [] = { "j " " b" "c"};
option
string temp = {"a", "b", "c"};
option
string temp [] = {"a", "b", "c"};
answer
4
q
prompt
what is the correct declaration of an abstract method that is intended to be
public:
type
single
option
public abstract void add();
option
public abstract void add() {}
option
public abstract add();
option
public virtual add();
answer
1
q
prompt
under what situations do you obtain a default constructor?
type
single
option
when you define any class
option
when the class has no other constructors
option
when you define at least one constructor
answer
2
q
prompt
which of the following can be used to define a constructor for this class, given
the following code:
code
public class test {
...
}
endcode
type
single
option
public void test() {...}
option
public test() {...}
option
public static test() {...}
option
public static void test() {...}
answer
2
q
prompt
which of the following are acceptable to the java compiler:
type
multiple
option
if (2 == 3) system.out.println("hi");
option
if (2 = 3) system.out.println("hi");
option
if (true) system.out.println("hi");
option
if (2 != 3) system.out.println("hi");
option
if (astring.equals("hello")) system.out.println("hi");
answer
1
answer
3
answer
4
answer
5
q
prompt
assuming a method contains code which may raise an exception (but not a
runtimeexception), what is the correct way for a method to indicate that it
expects the
caller to handle that exception:
type
single
option
throw exception
option
throws exception
option
new exception
option
don't need to specify anything
answer
2
q
prompt
what is the result of executing the following code, using the parameters 4 and 0:
code
public void divide(int a, int b) {
try {
int c = a / b;
} catch (exception e) {
system.out.print("exception ");
} finally {
system.out.println("finally");
}
endcode
type
singe
option
prints out: exception finally
option
prints out: finally
option
prints out: exception
option
no output
answer
1
q
prompt
which of the following is a legal return type of a method overloading the
following method:
code
endcode
type
single
option
void
option
int
option
can be anything
answer
3
q
prompt
which of the following statements is correct for a method which is overriding the
following method:
code
endcode
type
single
option
the overriding method must return void
option
the overriding method must return int
option
the overriding method can return whatever it likes
answer
1
q
prompt
given the following classes defined in separate files, what will be the effect of
compiling and running this class test?
code
class vehicle {
public void drive() {
system.out.println("vehicle: drive");
}
}
endcode
type
single
option
an indexoutofbounds exception is raised.
option
the vector grows in size to a capacity of 10 elements
option
the vector grows in size to a capacity of 15 elements
option
nothing, the vector will have grown when the fifth element was added
answer
3
q
prompt
what is the result of executing the following code when the value of x is 2:
code
switch (x) {
case 1:
system.out.println(1);
case 2:
case 3:
system.out.println(3);
case 4:
system.out.println(4);
}
endcode
type
single
option
nothing is printed out
option
the value 3 is printed out
option
the values 3 and 4 are printed out
option
the values 1, 3 and 4 are printed out
answer
3
q
prompt
consider the following example:
code
class first {
public first (string s) {
system.out.println(s);
}
}
public class second extends first {
public static void main(string args []) {
new second();
}
}
endcode
type
single
what is the result of compiling and running the second class?
option
nothing happens
option
a string is printed to the standard out
option
an instance of the class first is generated
option
an instance of the class second is created
option
an exception is raised at runtime stating that there is no null parameter
constructor in class first.
option
the class second will not compile as there is no null parameter constructor in the
class first
answer
6
q
prompt
what is the result of executing the following fragment of code:
code
boolean flag = false;
if (flag = true) {
system.out.println("true");
} else {
system.out.println("false");
}
endcode
type
single
option
true is printed to standard out
option
false is printed to standard out
option
an exception is raised
option
nothing happens
answer
1
q
prompt
consider the following classes. what is the result of compiling and running this
class?
code
public class test {
public static void test() {
this.print();
}
public static void print() {
system.out.println("test");
}
public static void main(string args []) {
test();
}
}
endcode
type
multiple
option
the string test is printed to the standard out.
option
a runtime exception is raised stating that an object has not been created.
option
nothing is printed to the standard output.
option
an exception is raised stating that the method test cannot be found.
option
an exception is raised stating that the variable this can only be used within an
instance.
option
the class fails to compile stating that the variable this is undefined.
answer
6
q
prompt
examine the following class definition:
code
public class test {
public static void test() {
print();
}
public static void print() {
system.out.println("test");
}
public void print() {
system.out.println("another test");
}
}
endcode
type
single
what is the result of compiling this class:
option
a successful compilation.
option
a warning stating that the class has no main method.
option
an error stating that there is a duplicated method.
option
an error stating that the method test() will call one or other of the print()
methods.
answer
3
q
prompt
what is the result of compiling and executing the following java class:
code
public class threadtest extends thread {
public void run() {
system.out.println("in run");
suspend();
resume();
system.out.println("leaving run");
}
<html>
<title>sample applet</title>
<body>
<applet code="sample.class" width=200 height=200></applet>
</body>
</html>
endcode
type
single
option
prints "hello world".
option
generates a runtime error.
option
does nothing.
option
generates a compile time error.
answer
2
q
prompt
what is the effect of compiling and (if possible) running this class:
code
public class calc {
public static void main (string args []) {
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, --j) {
system.out.println(" i = " + i + " : j = " + j);
total += (i + j);
}
system.out.println("total " + total);
}
}
endcode
type
single
option
produce a runtime error
option
produce a compile time error
option
print out "total 0"
option
generate the following as output:
list
i = 0 : j = 10
i = 1 : j = 9
i = 2 : j = 8
total 30
endlist
answer
3
qend