本帖最后由 佘天宇 于 2012-10-5 15:15 编辑
- package cn.itcast.problem;
- class Fu{
- private final void doSomething(){
- System.out.println("------fu.doSoething()----");
- }
- final void doSomething2(){
- System.out.println("-------fu.doSomething2()---");
- }
-
- public void doSomething3(){
- System.out.println("--------fu.doSomething3()----");
- }
- }
- class Zi extends Fu{
- public final void doSomething(){
- System.out.println("------zi.doSomething()----");
- }
-
- public void doSomething3(){
- System.out.println("------zi.doSomething3()----");
- }
- }
- public class ForFinalTest {
- public static void main(String[] args) {
- Zi z=new Zi();
- z.doSomething();
- z.doSomething2();
- z.doSomething3();
-
- /* 运行结果:
- * ------zi.doSomething()----
- -------fu.doSomething2()---
- ------zi.doSomething3()----
- 这子类的doSomething()方法是对父类的复写么,不是说final修饰不可以,
- 求解释?
-
-
- */
- }
- }
复制代码 |