Escolar Documentos
Profissional Documentos
Cultura Documentos
boolean, byte, char, double, float, int, long, and short (*)
boolean, byte, string, thread, int, double, long and short
object, byte, string, char, float, int, long and short
boolean, thread, stringbuffer, char, int, float, long and short
boolean, thread, char, double, float, int, long and short
2.
< (*)
<= (*)
=
!= (*)
All of the above.
3.
What is the output of the following lines of code?
int j=6,k=4,m=12,result;
result=j/m*k;
System.out.println(result);
2
0 (*)
48
24
4.
A local variable has precedence over a global variable in a Java method. True or false?
True (*)
5.
False
total cost: + 40
total cost: 48
total cost: 40 (*)
"total cost: " 48
"total cost: " 40
6.
What is the result when the following code segment is compiled and executed?
7.
!(3<4&&6>6||6<=6&&7-2==6)
True (*) False
8.
In an if-else construct the condition to be evaluated must end with a semi-colon. True or false?
True
False (*)
9.
Which of the two diagrams below illustrate the general form of a Java program?
Example A
Example B (*)
10.
In a For loop the counter is not automatically incremented after each loop iteration. Code must be written to increment
the counter. True or false?
True (*)
False
11.
When the For loop condition statement is met the construct is exited. True or false?
True
False (*)
12.
You can return to the Eclipse Welcome Page by choosing Welcome from what menu?
File
Edit
Help (*)
Close
13.
In Eclipse, when you run a Java Application, where may the results display?
Editor Window
Console View (*)
Debug View
Task List
None of the above
14.
A workspace
A physical location
A perspective (*)
All of the above
15.
What are the Eclipse Editor Area and Views used for?(Choose all correct answers)
17.
Updating the input of a loop allows you to implement the code with the next element rather than repeating the code
always with the same element. True or false?
True (*)
False
18.
One advantage to using a WHILE loop over a FOR loop is that a WHILE loop always has a counter. True or false?
True
False (*)
19.
Which of the following could be a reason to use a switch statement in a Java program?
Because it allows the code to be run through until a certain conditional statement is true.
Because it allows the program to run certain segments of code and neglect to run others based on the input given. (*)
Because it terminates the current loop.
Because it allows the user to enter an input in the console screen and prints out a message that the user input was successfully read
in.
20.
In Java, an instance field referenced using the this keyword generates a compilation error. True or false?
True
False (*)
21.
Consider
A constructor must have the same name as the class it is declared within. True or false?
True (*)
False
23.
Which of the following keywords are used to control access to the member of a class?
24.
default
public (*)
class
All of the above.
None of the above.
Which of the following creates a method that compiles with no errors in the class?
(*)
25.
The following code creates an Object of type Horse. True or false?
Whale a=new Whale();
True
False (*)
26.
What operator do you use to call an object's constructor method and create a new object?
+
new (*)
instanceOf
27.
Which of the following declares a one dimensional array name scores of type int that can hold 14 values?
int scores;
int[] scores=new int[14]; (*)
int[] scores=new int[14];
int score= new int[14]
28.
What is the output of the following segment of code if the command line arguments are "a b c d e f"?
1
3
5
6 (*)
30.
Which of the following declares a one dimensional array named names of size 8 so that all entries can be Strings?
String names=new String[8];
String[] name=new Strings[8];
String[] names=new String[8]; (*)
String[] name=String[8];
31.
String s="\\\\\
System.out.println(s);
"\\\\\"
\\\\\\\\
\\
\\\\ (*)
32.
88888 (*)
88888888
1010778
101077810109
ArrayIndexOutofBoundsException is thrown
33.
String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);
Which of the following would equate to false?
s1 == s2
s1 = s2
s3 == s1 (*)
s1.equals(s2)
s3.equals(s1)
34.
How would you use the ternary operator to rewrite this if statement?
If an exception is thrown by a method, where can the catch for the exception be?
Choose the best response to this statement: An error can be handled by throwing it and catching it just like an exception.
True. Errors and exceptions are the same objects and are interchangeable.
False. An error is much more severe than an exception and cannot be dealt with adequately in a program. (*
True. Although errors may be more severe than exceptions they can still be handled in code the same way exceptions are.
False. Exceptions are caused by a mistake in the code and errors occur for no particular reason and therefore cannot be
handled or avoided.
37.
39.
Which of the following is the correct way to call an overriden method needOil() of a super class Robot in a subclass
SqueakyRobot?
Robot.needOil(SqueakyRobot);
SqueakyRobot.needOil();
super.needOil(); (*)
needOil(Robot);
40.
41.
False
42.
43.
Static classes are designed as thread safe class instances. True or false?
True
False (*)
44.
Public static variables can't have their value reset by other classes. True or false?
True
False (*)
45.
Choose the correct implementation of a public access modifier for the method divide.
divide(int a, int b, public) {return a/b;}
public divide(int a, int b) {return a/b;} (*)
divide(int a, int b) {public return a/b;}
divide(public int a, public int b) {return a/b;}
46.
47.
Which segment of code represents a correct way to call a variable argument method counter that takes in integers as its
variable argument parameter?
counter(String a, int b);
counter(int[] numbers);
counter(1, 5, 8, 17, 11000005); (*)
counter("one","two",String[] nums);
48.
Classes
Methods
Local variables
Method parameters
All of the above (*)
49.
Joe is a college student who has a tendency to lose his books. Replacing them is getting costly. In an attempt to get organized, Joe
wants to create a program that will store his textbooks in one group of books, but he wants to make each book type the subject of
the book (i.e. MathBook is a book). How could he store these different subject books into a single array?
By ignoring the subject type and initializing all the book as objects of type Book.
By overriding the methods of Book.
Using polymorphism. (*)
This is not possible. Joe must find another way to collect the books.
50.
What is Polymorphism?
A way of redefining methods with the same return type and parameters.
A way to create multiple methods with the same name but different parameters.
A class that cannot be initiated.
The concept that a variable or reference can hold multiple types of objects. (*)