Você está na página 1de 7

1.

What are Java's simple types?

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.

Which of the following are relational operators in Java?

(Choose all correct answers)

< (*)
<= (*)
=
!= (*)
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

What does the following program output?

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?

int x = 22, y = 10;


double p = Math.sqrt( ( x + y ) /2);
System.out.println(p);

7.

Syntax error "sqrt(double) in java.lang.Math cannot be applied to int"


4.0 is displayed (*)
2.2 is displayed
5.656854249492381 is displayed
ClassCastException
Determine whether this boolean expression evaluates to true or false:

!(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 combination of views and editors are referred to as _______________.

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)

To modify elements. (*)


To navigate a hierarchy of information. (*)
To choose the file system location to delete a file.
16.
What is the output of the following code segment:
int n = 13;
System.out.print(doNothing(n));
System.out.print(" ", n);
where the code from the function doNothin is:
public double doNothing(int n)
{
n = n + 8;
return (double) 12/n;
}
1.75, 13
0.571, 21
1.75, 21
0.571, 13 (*)

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

public class YourClass{ public YourClass(int i){/*code*/} // more code...}


To instantiate YourClass, what would you write?
YourClass y = new YourClass();
YourClass y = new YourClass(3); (*)
YourClass y = YourClass(3);
YourClass y = YourClass();
None of the above.
22.

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?

(*)

All of the above.


None of the above

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.

Which of the following statements is not a valid array declaration?


int number[];
float []averages;
double marks[5];
counter int[]; (*)
29.

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.

What will the following code segment output?

String s="\\\\\
System.out.println(s);
"\\\\\"
\\\\\\\\
\\
\\\\ (*)
32.

Consider the following code snippet.

What is printed? Mark for Review


(1) Points

88888 (*)
88888888
1010778

101077810109
ArrayIndexOutofBoundsException is thrown

33.

Given the code

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 (balance < 500)


fee = 10;
else
fee = 0;

fee = ( balance < 500) ? 0 : 10;


fee= ( balance < 500) ? 10 : 0; (*)
fee = ( balance >= 5) ? 0 : 10;
fee = ( balance >= 500) ? 10 : 0;
fee = ( balance > 5) ? 10 : 0;
35.

If an exception is thrown by a method, where can the catch for the exception be?

There does not need to be a catch in this situation.


The catch must be in the method that threw the exception.
The catch can be in the method that threw the exception or in any other method that called the method that threw the
exception. (*)
The catch must be immediately after the throw.
36.

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.

Which of the following could be a reason to throw an exception?

To eliminate exceptions from disrupting your program. (*)


You have a fatal error in your program.
You have encountered a Stack Overflow Error.
To make the user interface harder to navigate.
38.
Suppose you misspell a method name when you call it in your program. Which of the following explains why this gives
you an exception?

Because the parameters of the method were not met.


Because the interpreter does not recognize this method since it was never initialized, the correct spelling of the method
was initialized.
Because the interpreter tries to read the method but when it finds the method you intended to use it crashes.
This will not give you an exception, it will give you an error when the program is compiled. (*)

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.

Why are hierarchies useful for inheritance?


They keep track of where you are in your program.
They restrict a superclass to only have one subclass.
They organize constructors and methods in a simplified fashion.
They are used to organize the relationship between a superclass and its subclasses. (*)

41.

It is possible for a subclass to be a superclass. True or false?


True (*)

False

42.

Static methods can write to instance variables. True or false?


True
False (*)

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.

Which of the following specifies accessibility to variables, methods, and classes?


Methods
Parameters
Overload constructors
Access specifiers (*)

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.

Which of the following can be declared final?

Classes
Methods
Local variables
Method parameters
All of the above (*)

49.

Which of the following would be most beneficial for this scenario?

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. (*)

Você também pode gostar