String a = null; a.concat(“abc”); a.concat(“def”); System.out.println(a); What is the result?()
第1题:
定义一个表示10个值为null的字符串数组,下面选项正确的是
A.String [] a;
B.String a[];
C.char a[10][];
D.String a[]=new String[10];
第2题:
已知String类定义如下:
class String
{
public:
String(const char *str = NULL); // 通用构造函数
String(const String &another); // 拷贝构造函数
~ String(); // 析构函数
String & perater =(const String &rhs); // 赋值函数
private:
char *m_data; // 用于保存字符串
};
尝试写出类的成员函数实现。
String::String(const char *str)
{
if ( str == NULL ) //strlen在参数为NULL时会抛
异常才会有这步判断
{
m_data = new char[1] ;
m_data[0] = '\0' ;
}
else
{
m_data = new char[strlen(str) + 1];
strcpy(m_data,str);
}
}
String::String(const String &another)
{
m_data = new char[strlen(another.m_data) + 1];
strcpy(m_data,other.m_data);
}
String& String::operator =(const String &rhs)
{
if ( this == &rhs)
return *this ;
delete []m_data; //删除原来的数据,新开一块内
存
m_data = new char[strlen(rhs.m_data) + 1];
strcpy(m_data,rhs.m_data);
return *this ;
}
String::~String()
{
delete []m_data ;
}
第3题:
C#中,string str = null 与 string str =””,请尽量用文字说明区别。(要点:说明详细的内存
空间分配)
第4题:
定义一个表示100个值为null的字符串数组,正确的选项是______。
A.String[ ]a;
B.String a[ ];
C.char a[100][ ];
D.String a[ ]=new String[100]
第5题:
以下( )表达式是不合法的。
A.String x="Sky";int y=5;x + =y:
B.String x="Sky":int y=5:if(x==y){}
C.String x="Sky":int y=5:x=x+y:
D.String x=null:int y=(x!=null) && (x.length( )>0)?x.length:0
第6题:
public static void main(String[] args) { String str = “null‟; if (str == null) { System.out.println(”null”); } else (str.length() == 0) { System.out.println(”zero”); } else { System.out.println(”some”); } } What is the result?()
第7题:
下面哪个是对字符串String的正确定义()。
第8题:
public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println( super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
第9题:
public static void main(String[]args){ String str="null"; if(str==null){ System.out.println("null"); }else(str.length()==0){ System.out.println("zero"); }else{ System.out.println("some"); } } What is the result?()
第10题:
Compilation fails.
An exception is thrown at runtime.
The variable first is set to null.
The variable first is set to elements[0].
第11题:
null
zero
some
Compilation fails.
An exception is thrown at runtime.
第12题:
smith,SALES
null,SALES
smith,null
null,null
第13题:
定义String s=null,会出现异常的选项是( )。 Ⅰ:if((s!=null)&(s.length()>0)) Ⅱ:if((s!=null)&&(s.length()>0)) Ⅲ:if(s==null)|(s.length()==0)) Ⅳ:if(s==null)||(s.length()==0))
A.Ⅱ、Ⅲ
B.Ⅱ、Ⅲ、Ⅳ
C.Ⅰ、Ⅲ
D.Ⅲ、Ⅳ
第14题:
已知类 String 的原型为
class string
{
public:
string(const char *str=null);//普通构造函数
string(const string &other);//拷贝构造函数
---string(void);
string &operate=(const string &other);//赋值函数
private:
char * m-data;//用于保存字符串
};
请编写 string 的上述4 个函数
第15题:
7 .string = null 和string = “”的区别
第16题:
在C#中,string str = null 与 string str = “” 请尽量使用文字或图象说明其中的区别。
第17题:
String[] elements = { “for”, “tea”, “too” }; String first = (elements.length > 0)? elements[0] null; What is the result?()
第18题:
public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println(super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
第19题:
下面哪些语句能够正确地生成5个空字符串?()
第20题:
JavaScript的基本数据类型包括String,boolean,Number,Undefined,Null。()
第21题:
You are consuming a Windows Communication Foundation (WCF) service in an ASP. NET Web application.The service interface is defined as follows:[ServiceContract]public interface ICatalog{ [OperationContract] [WebGet(UriTemplate="/Catalog/Items/{id}", ResponseFormat=WebMessageFormat.Json)] string RetrieveItemDescription(int id); } The service is hosted at Catalogsvc.You need to call the service using jQuery to retrieve the description of an item as indicated by a variable named itemId. Which code segment should you use?()
第22题:
Compilation fails.
An exception is thrown at runtime.
The variable first is set to null.
The variable first is set to elements[0].
第23题:
null
zero
some
Compilationfails.
Anexceptionisthrownatruntime.
第24题:
String s1=null;
String s2=’null’;
String s3=(String)‘abc’;
String s4=(String)‘/uface’;