Question 11.
Select the range of 'char'
A.-(2 power 7) TO (2 power 7)-1
B.-(2 power 15) TO (2 power 15)-1
C.0 TO (2 power 16)-1
D.0 TO 255
They gave C and D as correct. Isnt it 0 TO (2 power 15)-1 ?
Question 18.
Given the following class definition in a file named MyClass.java,
import java.io.IOException;
public class MyClass{
int i;
public void amethod(){
try{
i = 10;
i++;
throw new IOException();
i--;
}
catch( IOException e){
i++;
}
finally{
i--;
System.out.println("i is : "+i);
}
} //end of amethod()
public static void main(String[] args){
MyClass mc = new MyClass();
mc.amethod();
} //end of main
} //end of class MyClass
What happens when we try to compile and run MyClass.java.
A.Code does't compile because of error Statement not
reached.
B.Code doesn't compiles because IOException cann't be
thrown explicitly
C.Code compiles & runs with output
i is : 11
D.Code compiles & runs with no output.
The correct answer is A. The error is at the line following the Throw statement.
I was totally unaware this would cause an error.
Question 29.
Given that method aMethod() throws BaseException, SubException and RuntimeException of the following exception hierarchy
java.lang.Exception
|
+ - - BaseException
|
+ - - SubException
|
+ - - java.lang.RuntimeException
Which of the following are legal
A.public class MyClass {
public void myMethod(){
aMethod();
}
}
B.public class MyClass{
public void myMethod() throws BaseException,RuntimeException{
aMethod();
}
}
C.public class MyClass{
public void myMethod() throws BaseException{
aMethod();
}
}
D.public class MyClass{
public void myMethod() throws Exception{
aMethod();
}
}
E.public class MyClass{
public void myMethod() throws RuntimeException {
aMethod();
}
}
They said C and D but I dont see anything wrong with B.
Question 34.
Which of the following are true about inner classes
A.Inner classes can only be instantiated in its outer class
B.Inner classes can be protected or private
C.Anonymous inner class can be both an explicit subclass
and implements an interface.
D.Anonymous inner classes declare and instantiated at the
same place.
E.An inner class can be static only when it's outer class
is static.
F.An instance of an Anonymous inner class can only be
created in it's outer class
They said B and D but I chose F as well.
[\quote]
SCJP
Visit my download page
SCJP
Visit my download page
SCJP
Visit my download page
[code]
import java.io.*;
class Throws {
public static void main(String[] args) {
try {
Throws t = new Throws();
t.aMethod();
}
catch(IOException e) {
}
}
void aMethod() throws IOException,RuntimeException {
System.out.println("HI");
}
}
[\code][\quote]
it compiles and runs fine.
[This message has been edited by Randall Twede (edited December 16, 2000).]
[This message has been edited by Randall Twede (edited December 16, 2000).]
[This message has been edited by Randall Twede (edited December 16, 2000).]
SCJP
Visit my download page
....
Originally posted by Sahir Shah:
1. "An instance of an anonymous or local inner class can only be created within the scope of its declaration "
This statement is true.
2. "An instance of an anonymous or local inner class is accessible only within the scope of its declaration "
This statement is false.
Creating an object is not the same as passing a reference to an object around.
Originally posted by Nasir Khan:
"An instance of an Anonymous inner class can only be created in it's outer class." is not correct, may be this example will explain that to you
class sup{
void smethod(){}
}
class cage{
static sup method(){
return new sup(){
void smethod()
{ System.out.println( "from anonymous class");}
};
} }
class calling{
public static void main(String st[]){
cage.method().smethod();
}
}
[This message has been edited by Nasir Khan (edited December 16, 2000).]
Get out of my mind! Look! A tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|