类和对象练习题

程序运行结果为:

17、阅读下列程序,写出程序运行的结果: class SuperClass{ int x=10; int y=20;

public void show(){

System.out.println(\我是父类的成员方法!\}

class SubClass extends SuperClass{ int z=30; }

public class JC {

public static void main(String[] args) { SuperClass father=new SuperClass(); SubClass child=new SubClass();

System.out.println(\父类SuperClass成员变量、\

System.out.println(\子类SubClass成员变量、\ } }

程序运行结果为:

18、阅读下列程序,写出程序运行的结果: public class Class431 {

public static void main(String[] args) { int a = 3; char m='a';

prt(\ prt(\

prt(\ prt(\ }

static float test1(char x, int y) { int z = x+y; return z; }

static float test2() { int a = 60;

for (int i = 8; i < 12; i++) a= a+i;

prt(\ return a; }

static void prt(String s) { System.out.println(s); } }

程序运行结果为:

19、阅读下列程序,写出程序运行的结果: public class Class432 { static int i=123;

public static void main (String[] args) { int i=456;

System.out.println(\中的 i=\ m1( ); m2( ); }

static void m1( ) { int i=789;

System.out.println(\中的 i=\ }

static void m2( ) {

System.out.println(\类变量 i=\ i+=6;

System.out.println(\加 6 后的类变量 i=\ } }

程序运行结果为:

20、下面程序的结果是什么? class Tester { int var;

Tester(double var) {

this.var = (int)var; }

Tester(int var) { this(\ }

Tester(String s) { this();

System.out.println(s); }

Tester(){

System.out.println(\ }

public static void main(String[] args) Tester t = new Tester(5); } }

程序运行结果为:

21、以下代码的运行结果是 class Base{ int i; Base(){ add(1);

System.out.println(i); }

void add(int v){ i+=v;

System.out.println(i); }

void print(){

System.out.println(i); } }

class MyBase extends Base{ MyBase(){ add(2); }

{ void add(int v){ i+=v*2;

System.out.println(i); } }

public class TestClu {

public static void main(String[] args) { go(new MyBase()); //System.out.println(); }

static void go(Base b){ b.add(8); //b.print(); } }

程序运行结果为:

22、以下代码的输出结果是下列哪个选项? class Base{Base(){

System.out.println(\ } }

public class Checket extends Base{ Checket(){

System.out.println(\ super(); }

public static void main(String argv[]){ Checket c = new Checket(); // super(); } }

程序运行结果为:

23、给定下面的代码,哪个选项在替代\后可以被编译并且改变变量oak的值?

联系客服:779662525#qq.com(#替换为@)