最后的强转,是把Sub转换成Base 吧
解决方案 »
- 关于int 问题求解.感谢
- Java 中的自动装箱和拆箱,有比较好的解释吗?
- (急急急)java执行linux命令的问题
- 一个我一直想不通的YY问题,并且强烈希望sun公司倒闭
- 弱智问题请教!如何安装下载的扩展包。
- JBuilder界面插件1.3.2,####最新####(20030627)
- 请教各位对JAVA程序安装打包的经验之谈!
- 请问如何用JAVA建立一个包含字符串的结构数组并赋值?
- float fl = 999.666; 不能这么赋值吗?请问错到哪里了?
- 代码编译没错,就是通不过是什么问题,求指导
- 刚学java,想问一个关于jdk的问题
- 测试ConcurrentHashMap是否读写安全
1. class TestA {
2. public void start() { System.out.println("TestA"); }
3. }
4. public class TestB extends TestA {
5. public void start() { System.out.println("TestB"); }
6. public static void main(String[] args) {
7. ((TestA)new TestB()).start();
8. }
9. }
What is the result?
A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.
Answer: B那为什么这个强转之后还是B呢
1. class TestA {
2. public void start() { System.out.println("TestA"); }
3. }
4. public class TestB extends TestA {
5. public void start() { System.out.println("TestB"); }
6. public static void main(String[] args) {
7. ((TestA)new TestB()).start();
8. }
9. }
What is the result?
A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.
Answer: B那为什么这个强转之后还是B呢
这需要强转吗?这不就是向上转型吗?
1. class TestA {
2. public void start() { System.out.println("TestA"); }
3. }
4. public class TestB extends TestA {
5. public void start() { System.out.println("TestB"); }
6. public static void main(String[] args) {
7. ((TestA)new TestB()).start();
8. }
9. }
What is the result?
A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.
Answer: B那为什么这个强转之后还是B呢
这需要强转吗?这不就是向上转型吗?呃,那上面那个为什么是强转呢
1. class TestA {
2. public void start() { System.out.println("TestA"); }
3. }
4. public class TestB extends TestA {
5. public void start() { System.out.println("TestB"); }
6. public static void main(String[] args) {
7. ((TestA)new TestB()).start();
8. }
9. }
What is the result?
A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.
Answer: B那为什么这个强转之后还是B呢
这需要强转吗?这不就是向上转型吗?
哥,类名是不能调用非静态方法的!!!应该就是这个问题。
1. class TestA {
2. public void start() { System.out.println("TestA"); }
3. }
4. public class TestB extends TestA {
5. public void start() { System.out.println("TestB"); }
6. public static void main(String[] args) {
7. ((TestA)new TestB()).start();
8. }
9. }
What is the result?
A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.
Answer: B那为什么这个强转之后还是B呢
这需要强转吗?这不就是向上转型吗?
哥,类名是不能调用非静态方法的!!!应该就是这个问题。它new了可以调用吧
调用成员变量看左边,
调用成员属性,先看左边有没有该方法,有则调用右边的该方法,因为该方法被覆盖了
(然后看优先级别)