云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 类和对象练习题

类和对象练习题

  • 62 次阅读
  • 3 次下载
  • 2025/6/14 13:47:52

System.out.println(\swap:circle1 =\ swap(circle1,circle2); System.out.println(\swap:circle1 = \ }

public static void swap(Circle x , Circle y){

System.out.println(\swap: x = \ y = \

Circle temp = x; x = y; y = temp;

System.out.println(\ x = \= \ } }

程序运行结果为:

11、下列程序的输出结果是什么? public class Foo{ static int i=0; static int j=0;

public static void main(String[] args){ int i=2; int k=3; int j=3;

System.out.println(“i + j is ”+ i + j); k = i +j;

System.out.println(“k is ”+k); System.out.println(“j is ”+ j); } }

程序运行结果为:

12、运行类C的输出结果是什么? class A{

public A(){

System.out.println(\default constructor of A y is

invoked\} }

class B extends A{ public B(){

System.out.println(\default constructor of B is invoked\ } }

public class C{

public static void main(String[] args){ B b = new B(); } }

程序运行结果为:

13、阅读下列程序写出输出结果: class A{

String s=\ void show(){

System.out.println(s); } }

class B extends A{

String s=\

void show() {

System.out.println(s); } }

public class TypeConvert{

public static void main(String args[]){ B b1;

B b2=new B();

A a1,a2; a1=(A)b2; a2=b2;

System.out.println(a1.s); a1.show();

System.out.println(a2.s); a2.show(); b1=(B)a1;

System.out.println(b1.s); b1.show();

System.out.println(b2.s); b2.show(); } }

程序运行结果为:

14、阅读下列程序,写出程序运行的结果: class A { int i, j;

public A(){ this.i=0; this.j=0; }

public void print(){ System.out.println (\}

class B extends A{ int m;

public B (int i, int j, int m){ super (); this.m=m; }

public void print (){System.out.println (\ m=\}

public class C{

public static void main(String args[]){ A a=new A();

B b=new B(1, 2, 3); a.print (); b.print (); } }}

程序运行结果为:

15、阅读下列程序,写出程序运行的结果: class Demo { public void test ()

{System.out.println (\public void test (int i) {System.out.println (i);} public void test (int a, int b) {System.out.println (a+b);} }

public class Test {

public static void main(String args[]){ Demo de=new Demo(); de.test(); de.test(5); de.test(6,8); } }

程序运行结果为:

16、阅读下列程序,写出程序运行的结果: class Cube{ int width; int height; int depth;

Cube(int x,int y,int z){ this.width=x; this.height=y; this.depth=z; }

public int vol(){

return width*height*depth;}} public class UseCube {

public static void main(String[] args) { Cube a=new Cube(3,4,5);

System.out.println(\长度=\ System.out.println(\体积=\ } }

搜索更多关于: 类和对象练习题 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

System.out.println(\swap:circle1 =\ swap(circle1,circle2); System.out.println(\swap:circle1 = \ } public static void swap(Circle x , Circle y){ System.out.println(\swap: x = \ y = \ Circle temp = x; x = y; y = temp; System.out.println(\ x = \= \ } } 程序运行结果为: 11、下列程序的输出结果是什么? public class Foo{ static int i=0; static int j=0; p

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com