12. Which statement is true?
A. An anonymous inner class may be declared as final
B. An anonymous inner class can be declared as private
C. An anonymous inner class can implement multiple interfaces
D. An anonymous inner class can access final variables in any enclosing scope
E. Construction of an instance of a static inner class requires an instance of the enclosing outer class.
-------------------------------------------------------------------------------------------------------------------------------------------------
13. Given:
1. package foo;
2.
3. public class Outer (
4. public static class Inner (
5. )
6. )
Which statement is true?
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
--------------------------------------------------------------------------------------------------------------------------------------------------
这是一个static inner class.所以A是正确的。
--------------------------------------------------------------------------------------------------------------------------------------------------
/**
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
*/
package foo;
public class Outer
{
public static class Inner
{
public void writeSt()
{
System.out.println("Hello");
}
}
}
class TryInner
{
public TryInner()
{
new Outer.Inner(); //-------------A is OK!!!! and C is wrong.
}
}
***************
/**
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
*/
package bar;
class TryPack
{
public static void main(String[] args)
{
System.out.println("Hello World!");
//new Inner(); -----------This line is wrong so D is wrong;
new foo.Outer.Inner(); // You should write like this. and B is wrong
}
}
************************The Answer is A
A. An anonymous inner class may be declared as final
B. An anonymous inner class can be declared as private
C. An anonymous inner class can implement multiple interfaces
D. An anonymous inner class can access final variables in any enclosing scope
E. Construction of an instance of a static inner class requires an instance of the enclosing outer class.
-------------------------------------------------------------------------------------------------------------------------------------------------
13. Given:
1. package foo;
2.
3. public class Outer (
4. public static class Inner (
5. )
6. )
Which statement is true?
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
--------------------------------------------------------------------------------------------------------------------------------------------------
这是一个static inner class.所以A是正确的。
--------------------------------------------------------------------------------------------------------------------------------------------------
/**
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
*/
package foo;
public class Outer
{
public static class Inner
{
public void writeSt()
{
System.out.println("Hello");
}
}
}
class TryInner
{
public TryInner()
{
new Outer.Inner(); //-------------A is OK!!!! and C is wrong.
}
}
***************
/**
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
*/
package bar;
class TryPack
{
public static void main(String[] args)
{
System.out.println("Hello World!");
//new Inner(); -----------This line is wrong so D is wrong;
new foo.Outer.Inner(); // You should write like this. and B is wrong
}
}
************************The Answer is A