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

类和对象练习题

来源:用户分享 时间:2025/5/23 0:43:51 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

String s1=new String(\ String s2=\ String s3=\

System.out.println(s1==s2);

System.out.println(s1.equals(s2)); System.out.println(s2==s3);

System.out.println(s2.equals(s3)); String s4=s1;

System.out.println(s1==s4);

System.out.println(s1.equals(s4)); } }

程序运行结果为:

4、public class Test {

private static void printArray(int[] arr) { for(int i=0;i< arr.length;i++) System.out.print(arr[i]+\ System.out.println(\ }

private static void changeValue(int value) { value*=2; }

private static void changeValue(int[] arr) { for(int i=0;i

public static void main (String[] args) { int[] arr={1,2,3,4,5}; changeValue(arr[0]); printArray(arr); changeValue(arr); printArray(arr); } }

程序运行结果为:

5、class MyException extends Exception { public MyException(String message) { super(message); } }

public class Test {

private static void fun1() throws MyException {

throw new MyException(\in fun1().\ }

private static void fun2() throws MyException { try { fun1(); }

catch(NullPointerException ex) { System.out.println(\、\ }

finally {

System.out.println(\ } }

public static void main (String[] args) { try {

fun2(); }

catch(MyException ex) {

System.out.println(\); }

catch(Exception ex) {

System.out.println(\ } } }

程序运行结果为:

6、下面是一个类的定义,请完成程序填空。 public class ___ _______ {

int x, y;

Myclass ( int , int ) // 构造方法 {

x=i; y=j; } }

程序运行结果为:

7、 下面是一个类的定义,请将其补充完整。 class ___ __ { String name; int age;

Student( ___ __ s, int i) { name=s; age=i; } }

程序运行结果为:

8、下面程序的功能是通过调用方法max()求给定的三个数的最大值,请将其补充完整。 public class Class1{

public static void main( String args[] ){ int i1=1234,i2=456,i3=-987;

System.out.println(\三个数的最大值、\ ); }

public static int max(int x,int y,int z) { int temp1,max_value; temp1=x>y?x:y;

max_value=temp1>z?temp1:z; return max_value; } }

程序运行结果为:

9、写出下列程序的输出结果 public class Test{

public static void main(String[] args){ Count myCount = new Count(); int times = 0;

for(int i=0;i<100;i++)

increment(myCount , times);

System.out.println(“count is” + myCount.count); System.out.println(“time is”+ times); }

public static void increment(Count c , int times){ c.count++; times++; } }

class Count{

public int count; Count(int c){ count =c; }

Count(){ count =1; } }

程序运行结果为:

10、阅读下列程序,写出程序运行的结果: class Circle { double radius;

public Circle(double r){ this.radius=r; } }

public class Test{

public static void main(String[] args){ Circle circle1 = new Circle(1); Circle circle2 = new Circle(2);

搜索更多关于: 类和对象练习题 的文档
类和对象练习题.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c2ba7u9xopd4ncj33rqpp_4.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top