1、以下程序的输出结果为答:classA{doublex=10;protecteddoubley=12;}classBextendsA{inty=0;voidg(){intx=10;x=x+1;y=y+100;System.out.println("x="+x);System.out.println("y="+y...
1、以下程序的输出结果为答:
class A
{ double x=10;
protected double y=12;
}
class B extends A
{
int y=0;
void g()
{ int x=10;
x=x+1;
y=y+100;
System.out.println("x= "+x);
System.out.println("y= "+y);
}
}
class Example
{
public static void main(String args[ ])
{
B b=new B();
int y=-100;
b.g();
}
}
2、以下程序的输出结果为答:
class Area
{
float getArea(float r)
{
return 3.14f*r*r;
}
double getArea(float x,int y)
{
return x+y;
}
int getArea(int x,int y)
{
return x*y;
}
public classExample
{
public static void main(String args[])
{
Area a=new Area();
System.out.println("area1:"+a.getArea(100));
System.out.println("area2:"+a.getArea(2,1));
}
}
3、以下程序的输出结果为答:
import java.io.*;
public class abc
{ public static voidmain(String args[ ])
{ AB s= new AB("Hello!","I love JAVA.");
System.out.println(s.toString( ));
}
}
class AB {
String s1;
String s2;
AB( String str1 , String str2 )
{ s1 = str1; s2 = str2; }
public String toString( )
{ return s1+s2;}
}
4、以下程序的输出结果为答:
import java.io.* ;
public class abc
{
public static void main(String args[ ])
{ int i , s = 0 ;
int a[ ] = {10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 };
for ( i = 0 ; i < a.length ; i ++ )
if ( a[i]%3 = = 0 ) s += a[i] ;
System.out.println("s="+s);
}
}
5、以下程序的输出结果为答:
publicclass Person {
String name;
intage;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
publicstaticvoid main(String[] args) {
Person c = new Person("Peter", 17);
System.out.println(c.name + " is " + c.age + " years old!");
}
}
展开