77范文网 - 专业文章范例文档资料分享平台

Ch4类和对象练习题之简答题(2)

来源:网络收集 时间:2019-06-11 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

(5) (6)

(7)

(8)

(9)

(10)

interface A{ void print(); }

interface A{ void print(){ } ; }

abstract class A{ protected int unfinished(); }

abstract class A{ abstract void unfinished(); } abstrace interface A extends I1,I2{ abstract void print(){ } ; }

abstract interface A{ print(); } 合法的是(4),(5),(6),(9),(10) 14、 下面程序有什么错误?

public class Test{

public static void main(String[] args){ nPrintln(“Welcome to Java!”,5);

}

public static void nPrintln(String message,int n){ int n=1;

for (int i=0;i

System.out.println(message); } }

定义了两个同名变量n

15、 下面程序有什么错误?

Public class Test{

public static void method(int x){ }

public static void method(int y){ return y; }

}

Method方法重复定义了,没有达到重载的条件。 16、 下面程序有什么错误?

Public class Test{

public static method1(int n,m){ n+=m;

method2(3.4);

}

public static int method2(int n){ if(n>0) return 1;

else if(n==0) return 0; else if(n<0) return -1; }

}

没有定义method1函数的返回类型。

17、 下面程序有什么错误?

(1) public class ShowErrors{

public static void main(String[] args){

ShowErrors t=new ShowErrors(5); }

}

ShowErrors(int)没有定义,应该是ShowErrors().

(2) public class ShowErrors{

public static void main(String[] args){ ShowErrors t=new ShowErrors(); t.x(); }

}

X()没有定义,实例不能引用。

(3) public class ShowErrors{ public void method1(){ Circle c;

System.out.println(“what is radius”+c.getRadius()); c=new Circle();

ShowErrors t=new ShowErrors(5); }

} ShowErrors(int)没有定义,应该是ShowErrors().

(4) public class ShowErrors{

public static void main(String[] args){ C c=new C(5.0);

System.out.println(c.value); } }

class C{

int value=2; }

C(int)没有定义,应该是C()

18、 下面代码中的错误是什么? public class Test{

public static void main(String[] args){ Object fruit=new Fruit(); Object apple=(Apple)fruit; } }

class Apple extends Fruit{ } class Fruit{ }

fruit不能被强制转换成apple 19、 下面的代码有什么错误? public class Test{

public static void main(String[] args){ Number x=new Integer(3);

System.out.println(x.intValue());

System.out.println((x.compareTo(new Integer(4))); } }

compareTo方法是字符类方法,Number里没有定义。 20、 下面的代码有什么错误? public class Test{

public static void main(String[] args){ Number x=new Integer(3);

System.out.println(x.intValue());

System.out.println(((Integer)x.compareTo(new Integer(4))); }

}

compareTo方法是字符类方法,Number里没有定义,且不能被强制转换。 21、

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Ch4类和对象练习题之简答题(2)在线全文阅读。

Ch4类和对象练习题之简答题(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/658809.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: