String a = null;  a.concat(“abc”);  a.concat(“def”);  System.out.println(a);   What is the result?()  A、 abcB、 nullC、 abcdefD、 Compilation fails.E、 The code runs with no output.F、 An exception is thrown at runtime.

题目

String a = null;  a.concat(“abc”);  a.concat(“def”);  System.out.println(a);   What is the result?()  

  • A、 abc
  • B、 null
  • C、 abcdef
  • D、 Compilation fails.
  • E、 The code runs with no output.
  • F、 An exception is thrown at runtime.

相似考题
更多“String a = null;”相关问题
  • 第1题:

    定义一个表示10个值为null的字符串数组,下面选项正确的是

    A.String [] a;

    B.String a[];

    C.char a[10][];

    D.String a[]=new String[10];


    正确答案:D
    解析:本题考查字符串数组变量的声明。选项A和选项B的效果是一样的,都是用来定义一个字符串数组,但没有指明数组个数,不满足题B-要求。选项C是一个二维的字符数组,在C语言中,一个二维的字符数组就可以表示一个一维的字符串数组,而在Java中,字符char是基本类型,字符串String则是以对象的形式来表示的。选项D正确,它定义了一个含有10个元素的字符串数组,如果没有给字符串数组赋值,则默认为null。

  • 第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 =””,请尽量用文字说明区别。(要点:说明详细的内存

    空间分配)


    正确答案:
    string str =”” 分配空间 

  • 第4题:

    定义一个表示100个值为null的字符串数组,正确的选项是______。

    A.String[ ]a;

    B.String a[ ];

    C.char a[100][ ];

    D.String a[ ]=new String[100]


    正确答案:D
    解析: 在C语言中,一个二维的字符型数组可以表示一个一维的字符串数组,而在Java语言中,字符char是基本类型,字符串String则是以对象的形式来表示的。选项D定义一个含有100个元素的字符串数组,如果未对字符串数组赋值,则默认值为null,所以选项D正确。

  • 第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


    正确答案:B

  • 第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?()

    • A、 null
    • B、 zero
    • C、 some
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:D

  • 第7题:

    下面哪个是对字符串String的正确定义()。

    • A、String s1=null;
    • B、String s2=’null’;
    • C、String s3=(String)‘abc’;
    • D、String s4=(String)‘/uface’;

    正确答案:A

  • 第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”)后程序的输出是哪项?() 

    • A、 smith,SALES
    • B、 null,SALES
    • C、 smith,null
    • D、 null,null

    正确答案:A

  • 第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?()

    • A、null
    • B、zero
    • C、some
    • D、Compilationfails.
    • E、Anexceptionisthrownatruntime.

    正确答案:D

  • 第10题:

    单选题
    String[] elements={"for","tea","too"}; String first=(elements.length>0)?elements[0]null; What is the result?()
    A

    Compilation fails.

    B

    An exception is thrown at runtime.

    C

    The variable first is set to null.

    D

    The variable first is set to elements[0].


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    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?()
    A

     null

    B

     zero

    C

     some

    D

     Compilation fails.

    E

     An exception is thrown at runtime.


    正确答案: C
    解析: 暂无解析

  • 第12题:

    单选题
    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”)后程序的输出是哪项?()
    A

     smith,SALES

    B

     null,SALES

    C

     smith,null

    D

     null,null


    正确答案: D
    解析: 暂无解析

  • 第13题:

    定义String s=null,会出现异常的选项是()。Ⅰ:if((s!=null)&(s.length()>0))Ⅱ:if((s!=null)&am

    定义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.Ⅲ、Ⅳ


    正确答案:C
    解析:本题是考查对逻辑运算符的理解。逻辑运算符&&、||,在运算中有“短路”行为:例如,A&&B,如果A的值为false,则直接将整个表达式的值置为false,对B的值不加考察。而运算符&、|就没有这种行为。所以在选项A、C中,s.length()会导致抛出空指针异常。

  • 第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 = “” 请尽量使用文字或图象说明其中的区别。


    正确答案:
    答:string str = null 是不给他分配内存空间,而string str =  给它分配长度为空字符串的内存空间。

  • 第17题:

    String[] elements = { “for”, “tea”, “too” };  String first = (elements.length > 0)? elements[0] null;  What is the result?()

    • A、 Compilation fails.
    • B、 An exception is thrown at runtime.
    • C、 The variable first is set to null.
    • D、 The variable first is set to elements[0].

    正确答案:D

  • 第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”)后程序的输出是哪项?() 

    • A、 smith,SALES
    • B、 null,SALES
    • C、 smith,null
    • D、 null,null
    • E、 编译错误

    正确答案:E

  • 第19题:

    下面哪些语句能够正确地生成5个空字符串?()

    • A、String a[]=new String[5];for(int i=0;i<5;a[i++]=“”);
    • B、String a[]={“”,“”,“”,“”,“”};
    • C、String a[5];
    • D、String[5]a;
    • E、String[]a=new String[5];for(int i=0;i<5;a[i++]=null);

    正确答案:A,B

  • 第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?()

    • A、$get(String.format("/Catalogsvc/Catalog/Items/id{0}", itemId) null, function (data) { ... }, javascript");
    • B、$get(String.format("/Catalogsvc/Catalog/Items/{0}", itemId), null, function (data) { ... }, "json");
    • C、$get(String.format("/Catalogsvc/Catalog/Items/{0}", itemld), null, function (data) { ... }, "xml");
    • D、$get(String.format("/Catalogsvc/Catalog/Items/id{0}", itemld), null, function (data) { ... }, "json");

    正确答案:B

  • 第22题:

    单选题
    Given: String[] elements = { "for", "tea", "too" }; String first = (elements.length > 0) ? elements[0] : null; What is the result?()
    A

    Compilation fails.

    B

    An exception is thrown at runtime.

    C

    The variable first is set to null.

    D

    The variable first is set to elements[0].


    正确答案: C
    解析: 暂无解析

  • 第23题:

    单选题
    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?()
    A

    null

    B

    zero

    C

    some

    D

    Compilationfails.

    E

    Anexceptionisthrownatruntime.


    正确答案: B
    解析: 暂无解析

  • 第24题:

    单选题
    下面哪个是对字符串String的正确定义()。
    A

    String s1=null;

    B

    String s2=’null’;

    C

    String s3=(String)‘abc’;

    D

    String s4=(String)‘/uface’;


    正确答案: C
    解析: 暂无解析