java程序阅读题

java程序阅读题,第1张

1、(1)此嫌true   false  (2)true代表s1和 s2值是一样的,false代表s1和s2的地址不一样。

2、(1)100   (2)错误,因为字符串“exit”不能转化成Integer对象

3、(1)看插图 (伍耐2)实现的接口是ActionListener,该接口的方法声明是public void actionPerformed(ActionEvent e)

4、 (1) size = 3

5   10   15

(2)森橘手set接口是不包括重复元素的集合,Map接口将键映射到值,value可以重复,但每个键最多只能映射一个值。

5、 (1)25     (2)终止应用程序的运行

LZ,9-11题的程序运行结果如下:

10、

汪汪

喵喵

呱呱

11、

100 dollars come.

All money come.

17、

package 拆猛test01

public class test4 {

public static void main(String[] args) {

B obj 晌孝= new B()

System.out.println( obj.f(4, 6))

}

}

class A {

double f(double x, double y) 旅谨桥{

return x * y

}

}

class B extends A {

double f(double x, double y) {

return x + y

}

}

输出结果:10.0

9、EAB ;

10、012345 ;

11、0 ;

public static void main(String args[]){

String s1="Java"

int n=s1.length() //得到s1这个字符串变量的长度

System.out.print("n="+n)

char m=s1.charAt(2)//得到s1变量中第三个字符

System.out.println(" s1="+s1)

}//n=4 s1=Java

2.以下程序的输出结果为 123 。

class Test{

static int num//定义扰携清一个静态变量

int c

public Test( ){

num++}

public static void main(String[ ] args){

Test x1=new Test()

System.out.print(x1.num)

Test x2=new Test()

System.out.print(x2.num)

Test x3=new Test()

System.out.println(x3.num)//获得x3对象中num属性的隐慎值 3

}}

3、以下程序的输出结果为 Inside main() Mug(1) c1 initialized Mugs()。

class Mug {

Mug(int marker) {

System.out.println("Mug(" + marker + ")") }

void f(int marker) {

System.out.println("f(" + marker + ")")}}

public class Mugs {

Mug c1

{ c1 = new Mug(1)//实例化对象c1

System.out.println("c1 initialized")}

Mugs() { System.out.println("Mugs()")}

public static void main(String[] args) {

System.out.println("Inside main()")

Mugs x = new Mugs()//实例化x

}}

4、以下程序的输出结果为 AB 。

class A{

public A(){

System.out.print(“ A ”)

}}

public class B extends A{//类B继承类A

public B(){

System.out.print(“ B ”)

}

public static void main(String[ ] args){

new B( )//初始化一个类B的临时变量缓前

}}

.public class AboutThreeNum

{public static void main(String[ ] args)

{ System.out.println( fun(-8, 50, 23) )}

static int fun(int x, int y, int z) //静态函数fun,属于这个类,而不是单个对象

{ return fun( x, fun(y,z) ) }

static int fun(int x,int y)

{ if(x>y)return x//当x>y时,返回x的值

else return y}}

结果 50


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8272756.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-14
下一篇2023-04-14

发表评论

登录后才能评论

评论列表(0条)

    保存