Java first quiz...

Java first quiz...

Select the correct answer from the option .. please read question carefully before answer ..

published on November 10, 20145 responses 0
Next »
1/5

An unchecked exception occurs in a method dosomething()
Should other code be added in the dosomething() method for it to compile and execute?

The Exception must be caught
The Exception must be declared to be thrown.
The Exception must be caught or declared to be thrown.
No other code needs to be added.
2/5

Given the code fragment:
interface SampleClosable {
public void close () throws java.io.IOException;
}
Which three implementations are valid?

public class Test implements SampleCloseable {
public void close() throws java.io.IOException {
/ / do something
}
}
public class Test implements SampleCloseable {
public void close() throws Exception {
/ / do something
}
}
public class Test implements SampleCloseable {
public void close() throws java.io.FileNotFoundException {
/ / do something
}
}
public class Test extends SampleCloseable {
public void close() throws java.IO.IOException {
/ / do something
}
}
3/5

public class SampleClass {
public static void main(String[] args) {
AnotherSampleClass asc = new AnotherSampleClass();
SampleClass sc = new SampleClass();
// TODO code application logic here
}
}
class AnotherSampleClass extends SampleClass {
}
Which statement, when inserted into line "// TODO code application logic here ", is valid change?

Hint: 2 choices
asc = sc;
sc = asc;
asc = (object) sc;
asc = sc.clone ()
4/5

Given the code fragment:
System.out.println("Result: " + 2 + 3 + 5);
System.out.println("Result: " + 2 + 3 * 5);
What is the result?

Result: 10
Result: 25
Result: 235
Result: 215
Result: 215
Result: 215
Result: 10
Result: 30
5/5

Which code fragment is illegal?

class Base1 {
abstract class Abs1 { }}
abstract class Abs1 {
void doit () { }
}
class Basel {
abstract class Abs1 extends Basel {
abstract int var1 = 89;