更多"[C++代码] class Product { //产品 privat"的相关试题:
[单项选择]假设有以下代码:
String s="hello";
String t="hello";
char c[]='h', 'e', 'l', 'l', 'o';
下列选项中,返回false的语句是______。
A. s.equals(t);
B. t.equals(c);
C. s==t;
D. t.equals (new String("hello"));
[单项选择]以下程序代码的输出结果是( )
String s=new String("abcdef"),t=new String("123");
System. out. println((concat(s,t)). length( ));
A. 9
B. 10
C. 6
D. 出错
[单项选择]指出下列程序运行的结果 ( )
public class Example
String str=new String("good");
char[]ch=’a’,’b’,’c’;
public static void main(String args[])
Example ex=new Example( );
ex.change(ex.otr,ex.ch);
System.out.print(ex.str+"and");
System.out.print(ex.ch);
public void change(String str,char ch[])
str="test ok";
ch[0]≈’g’;
A. good and abc
B. good and gbc
C. test ok and abc
D. test ok and gbc
[单项选择]下列程序的运行结果是() public class test{ private String[] data={“10”,“10.5”}; public void fun(){ double s=0; for(int i=0;i<3;i++){ try{ s=s+Integer .parseInt(data[i]); }catch(Exception e){ System.out.print(“errorl:”+data[i]); } } } public static void main(String[]args){ try{ testd=new test(); d .fun(); }catch(Exception e){ System.out.printIn(“error2”); } } }
A. errorl:10.5
B. error2
C. errorl:10.5 error2
D. 以上都不对
[填空题]下面是一个类的定义,试将程序补充完整。
class Test
String s;
【12】 int a =66;
Test(String s1)
s=s1;
static int geta( )
return a;
[简答题]阅读以下程序代码,写出程序的功能。
public class Class34
public static void main(String[] args)
int a=1,b;
while(a<=9)
b=1;
while(b<=a)
System. out. print(" "+a+"×"+b+"="+a*b);
b++;
System. out. println( );
a++;
[单项选择]下列代码段声明了3个类:
class Person;
class Student:public Person;
class Undergraduate:Student;
下列关于这些类之间关系的描述中,错误的是( )。
A. 类Person是类Undergraduate的基类
B. 类Undergraduate从类Student公有继承
C. 类Student是类Person的派生类
D. 类Undergraduate是类Person的派生类
[填空题]下列是一个类的定义,将程序段补充完整。
class A {
String s;
【 】int a=66;
A(String sl) { s=sl;}
static int geta( ) { return a;}
}
[简答题]阅读以下程序代码,写出程序的输出结果。
public class Class35
public static void main(String[] args)
String s1=new String("0860371"),s2="0860371";
System. out. println(s1==s2);
System. out. println(s1. equals(s2));
System. out. println(s1. endsWith(s2)==s1. startsWith(s2));
[简答题]阅读以下程序代码,写出程序的输出结果。
public class Class32
public static void main(String[] args)
boolean x=true,y=false,z=false;
x=x&&y||z;
y=x||y&&z;
z=!(x!=y)||(y==z);
System. out. println(x+","+y+","+z);
[简答题]阅读以下程序代码,写出程序的输出结果。
public class Class33
public static void main(String[] args)
int a,b,c;
a=b=c=1;
boolean w;
w=a++>1&&++b>c++:
System. out. println(a+","+b+","+c+","+w);
[单项选择]下面代码不合法之处是( )
class Class6
int x;
void f( )
int class 6=1;①
x=class 6;②
void g( )
int y;③
y=class6+x;④
A. 语句①
B. 语句②
C. 语句③
D. 语句④
[单项选择]阅读下面代码
public class Arrays
public static void main(String[] args)
int[] a=new int[5];
for(int i=0;i<a.length;i=i+1)a[i]=10+i;
for(int i=0;i<a.length;i=i+1)System.out.println(a[i]);
String[] s="Frank","Bob","Jim";
for(int i=0;i<s.length;i=i+1)System.out.println(s[i]);
s[2]="Mike";
System.out.println(s[2]);
代码运行正确的结果是
A. 10
B. 11
C. 10
D. 11
[单项选择]阅读下面代码
public class Jixiangwu
public static void main(String[] args)
String[] stars="贝贝","晶晶","欢欢","迎迎","妮妮";
System.out.println("你抽取的奥运吉祥物是"+
"“"+stars[(int)(stars. ______ *Math.random( ))]+"”"+"!");
为保证程序能正确执行,程序中下画线处应填写的是
A. long
B. width
C. wide
D. length
[单项选择]阅读下面代码
public class Test implements Runnable
public void run(Thread t)
System.out.println("Running");
public static void main(String[] args)
Thread tt=new Thread(new Test( ));
tt.start( );
代码运行的结果是
A. 将抛出一个异常
B. 没有输出并正常结束
C. 输出“Running”并正常结束
D. 程序第2行将出现一个编译错误