求JAVA读程序题答案~
三、读程序,写结果
15.class Parent
{ void printMe()
{System.out.println("parent!");} }
class Child extends Parent
{ void printMe()
{System.out.println("child!");}
void printAll()
{super.printMe();this.printMe(); printMe(); } }
public class Test_this
{ public static void main(String args[])
{ Child myC=new Child();
myC.printAll(); }}
16.public class Example
{ public static void main(String args[ ])
{ int n=0,m=0,t=555;
try{ m=Integer.parseInt("8888");
t=9999;
}
catch(
NumberFormatException e)
{ System.out.println("发生异常:"+e.getMessage());
e.printStackTrace();
n=123;
}
System.out.println("n="+n+",m="+m+",t="+t);
}
}
17.public class MyThread
{ public static void main(String args[])
{ Lefthand left=new Lefthand();
Righthand right=new Righthand();
left.start();right.start();}}
class Lefthand extends Thread
{ public void run()
{ int i;
for(i=0;i<3;i++)
{ System.out.print("red");
try
{ sleep(300);}
catch(InterruptedException e){}
}}}
class Righthand extends Thread
{ public void run()
{ int i;
for(i=0;i<3;i++)
{ System.out.print("blue");
try
{ sleep(300); }
catch(InterruptedException e){}
}}}
18.public class ContinueDemo
{public static void main(String[] args)
{ int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{ if(i==j) continue;
System.out.println("j="+j);}
System.out.println("i="+i); } }
------解决方案--------------------
15 老子 儿子 儿子
16 n=0,m=8888,t=9999
18 j=1
j=2
j=0
j=2
j=0
j=1
i=3
说明:17题 我也是新手不会