Would u pls answer my questions on the mock exam from China IT Lab.
Q2. "A class defined within a method can only access final methods of the enclosing method" is true
Why there is 'final methods' the enclosing method?
Does it means that the enclosing method contains final method which is accessible by inner class?
Q7.
class A{
protected int i;
A(int i){
this.i=i;
}
}
The answer said that the following class B is NOT a valid inner class for A.
class B{
B(){
System.out.println("i = "+i );
}
}
But why? I have tried the code and it CAN compile!!
Q83.
What will happen when try to compile and run the following code?
public class CEx{
public static void main(String argv[]){
Base b = new Base();
Sub s = (Sub)b;
}
}
class Base{}
class Sub extends Base{}
class Sub2 extends Base{}
Answer: It will give Runtime exception.
I tried this code and found that it gave ClassCastException.
Is the ClassCastException ALWAYS given when an instance is casted down?
thx a lot!