单选题:What will happen when you attempt to compile and run this code?
What will happen when you attempt to compile and run this code? @[D](2)
```Java
class Base{
public final void amethod(){
System.out.println("amethod");
}
}
public class Fin extends Base{
public static void main(String argv[]){
Base b = new Base();
b.amethod();
}
}
```
A. Compile time error indicating that a class with any final methods must be declared final itself
B. Compile time error indicating that you cannot inherit from a class with final methods
C. Run time error indicating that Base is not defined as final
D. Success in compilation and output of "amethod" at run time.
A.Compile time error indicating that a class with any final methods must be declared final itself
B.Compile time error indicating that you cannot inherit from a class with final methods
C.Run time error indicating that Base is not defined as final
D.Success in compilation and output of "amethod" at run time.
答案:D
```Java
class Base{
public final void amethod(){
System.out.println("amethod");
}
}
public class Fin extends Base{
public static void main(String argv[]){
Base b = new Base();
b.amethod();
}
}
```
A. Compile time error indicating that a class with any final methods must be declared final itself
B. Compile time error indicating that you cannot inherit from a class with final methods
C. Run time error indicating that Base is not defined as final
D. Success in compilation and output of "amethod" at run time.
A.Compile time error indicating that a class with any final methods must be declared final itself
B.Compile time error indicating that you cannot inherit from a class with final methods
C.Run time error indicating that Base is not defined as final
D.Success in compilation and output of "amethod" at run time.
答案:D