A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 空白心 中级黑马   /  2015-6-15 00:29  /  619 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

写出程序结果
[java] view plaincopy
class Demo  
{  
    public static void main(String[] args)  
    {  
        try  
        {  
            showExce();  
            System.out.println("A");  
        }  
        catch (Exception e)  
        {  
            System.out.println("B");  
        }  
        finally  
        {  
            System.out.println("C");  
        }  
        System.out.println("D");  
    }  
    public static void showExce()throw Exception   
    {  
        throw new Exception();  
    }  
}  

结果是:  B
C
D


14.写出程序结果
[java] view plaincopy
class Super  
{  
    int i=0;  
    //Super(){}  
    public Super(String s)  
    {  
        i=1;  
    }  
}  
class Demo extends Super  
{  
    public Demo(String s)  
    {  
        i=2;  
    }  
    public static void main(String[] args)   
    {  
        Demo d=new Demo("yes");  
        System.out.println(d.i);  
    }  
}  

结果是:编译失败,因为父类中缺少空参数的构造函数或者子类应该通过Super语句指定要调用的父类中的构造   
      函数



15.写出程序结果
[java] view plaincopy
class Super  
{  
    public int get()  
    {  
        return 4;  
    }  
}  
class Demo15 extends Super  
{  
    public long get()  
    {  
        return 5;  
    }  
    public static void main(String [] args)  
    {  
        Super s=new Demo15();  
        System.out.println(s.get());  
    }  
}  
结果是:编译失败,因为子类父类中的get方法没有覆盖但是子类调用时候不能明确返回值是什么类型的。
                      所以这样的函数不能存在于子父类中。


16.写出程序结果
[java] view plaincopy
class Demo  
{  
    public static void func()  
    {  
        try  
        {  
            throw new Exception;  
            System.out.println("A");  
        }  
        catch (Exception e)  
        {  
            System.out.println("B");  
        }  
    }  
    public static void main(String [] args)  
    {  
        try  
        {  
            func();  
        }  
        catch (Exception e)  
        {  
            System.out.println("C");  
        }  
        System.out.println("D");  
    }  
}

2 个回复

倒序浏览
赞 赞         赞!!!!!!!!!!!!
回复 使用道具 举报
:lol赞一个
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马