更多“下列语句创建了多少个string对象()。string[,]strArray=new string[3][4];A、0B、3C、4D、12”相关问题
  • 第1题:

    阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写对应栏内。

    【说明】

    下面的程序实现了类String的构造函数、析构函数和赋值函数。

    已知类String的原型为:

    class String

    {

    public:

    String(coust char * str = NULL); //普通构造函数

    String( const String &other); //拷贝构造函数

    ~String(void); //析构函数

    String & perate =(const String &other); //赋值函数

    private:

    char * m_data; // 用于保存字符串

    };

    //String 的析构函数

    String:: ~String (void)

    {

    (1);

    }

    //String 的普通构造函数

    String: :String( const char * str)

    {

    if (2)

    {

    m_data = new char[1];

    *m_data = '\0';

    }

    else

    {

    int length = strlen(str);

    m_data = new ehar[ length + 1 ];

    strepy(m_data, str);

    }

    }

    //拷贝的构造函数

    String:: String( const String &other)

    { int length = strlen(other. m_data);

    m_data = new char[ length + 1 ];

    strepy(m_data, other, m_data); //赋值函数

    String & String::operate = (eonst String &other) //

    {

    if (3)

    return * this;

    delete [] m_clara; //释放原有的内存资源

    int length = strlen( other, m_data);

    m_data = new chart length + 1 ];

    (4);

    return (5);

    }


    正确答案:(1)delete[]m_data或者delere m_data
    (1)delete[]m_data或者delere m_data 解析:由于m_data 是内部数据类型,也可以写成delete m_data。

  • 第2题:

    下列( )语句是声明一个含有10个String对象的数组。

    A.char str [];

    B.char str [] [];

    C.String str[]=new String[10];

    D.String str[10];


    正确答案:C

  • 第3题:

    下列语句输出结果为( )。 public class test { public static void main(StringArgsl[]) { String s1=new String("How"); String s2=new String("How"); System.out.println(!(s1==s2)); } }

    A.false

    B.true

    C.1

    D.0


    正确答案:B

  • 第4题:

    类Student代码如下:  class Student{    String name;  int age;  Student(String nm){  name = nm; } }  执行语句Student stu = new Student()后,字段age的值是哪项?() 

    • A、 0
    • B、 null
    • C、 false
    • D、 编译错误

    正确答案:D

  • 第5题:

    下列哪个语句是声明了一个含有10个string对象的数组()。

    • A、char str[];
    • B、char str[][];
    • C、string str[]=newstring[10];
    • D、string str[10];

    正确答案:C

  • 第6题:

    下面关于数组声明和初始化的语句哪个有语法错误()

    • A、int a1[]={3,4,5};
    • B、String a2[]={"string1","string1","string1"};
    • C、String a3[]=new String(3);
    • D、int[][] a4=new int[3][3];

    正确答案:C

  • 第7题:

    在C#中,下列哪条语句能创建一个具有3个初始值为""的元素的字符串数组?()

    • A、string StrList[3]("");
    • B、string[3] StrList={"","",""};
    • C、string[] StrList={"","",""};
    • D、string[] StrList=new string[3];

    正确答案:C

  • 第8题:

    现有:   class TestFoo {   int x;   String y;   int getX() { return x; }   String getY() { return y; }   void setX(int x) {   int z = 7;   this.x = x;   }    }    可以添加多少个修饰符来封装此类?() 

    • A、 2
    • B、 3
    • C、 4
    • D、 5

    正确答案:A

  • 第9题:

    类Student代码如下:D   class Student{   String name;   int age;   Student(String nm){ (构造方法)   name = nm;  }  }   执行语句Student stu = new Student()后,字段age的值是哪项?()

    • A、 0
    • B、 null
    • C、 false
    • D、 编译错误

    正确答案:D

  • 第10题:

    Given: 11.String test = "This is a test"; 12.String[] tokens = test.split("/s"); 13.System.out.println(tokens.length); What is the result?()

    • A、0
    • B、1
    • C、4
    • D、Compilation fails.

    正确答案:D

  • 第11题:

    单选题
    现有:   class TestFoo {   int x;   String y;   int getX() { return x; }   String getY() { return y; }   void setX(int x) {   int z = 7;   this.x = x;   }    }    可以添加多少个修饰符来封装此类?()
    A

     2

    B

     3

    C

     4

    D

     5


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

  • 第12题:

    问答题
    String s = new String("xyz");创建了几个String Object?

    正确答案: 两个对象,一个是“xyx”,一个是指向“xyx”的引用对象s。
    解析: 暂无解析

  • 第13题:

    下列语句能给数组赋值而不使用for循环的是

    A.myArray{[1]="One";[2]="Two";[3]="Three";}

    B.String s[5]=new String[]{"Zero", "One", "Two", "There", "Four"};

    C.String s[]=new String[]{"Zero", "One", "Two", "There", "Four"};

    D.String s[]=new String[]=|"Zero", "One", "Two", "There", "Four"};


    正确答案:C
    解析:A)、D)语法不正确,B)中s[5]的形式只能通过for循环的格式进行赋值,而不能直接赋值。C)中表达式左侧的“[]”说明现在定义一个数组,不需要指明数组长度,而表达式右侧“[]”在后面直接紧跟初始内容时也是不需要指定数组大小的,数组大小直接由初值长度决定。

  • 第14题:

    String s = new String("xyz");创建了几个String Object?

    二者之间有什么区别?


    正确答案:

     

    两个,一个放在常量区,不管写多少遍,都是同一个。New String 每写一遍,就创建一个新。

  • 第15题:

    下列语句能给数组赋值,而不使用for循环的是

    A.myArray{[1]="One";[2]="Two";[3]="Three";}

    B.String s[5]=new String[] {"Zero","One","Two","Three","Four"};

    C.String s[]=new String[] {"Zero","One","Two","Three","Four"};

    D.String s[]=new String[]= {"Zero","One","Two","Three","Four"};


    正确答案:C
    解析:字符串数组赋初值的方法有两种,一种是如选项C一样初始化。另外一种是先为每个数组元素分配引用空间,再为每个数组元素分配空间并赋初值。例如还可做如下赋值:
      string s[]=new String[5];
      s[0]="Zero";
      s[1]="One";
      s[2]="Two";
      s[3]="Three";
      s[4]="Four";

  • 第16题:

    哪个语句创建了一个数组实例?()

    • A、int[] ia= new int [15];
    • B、float fa= new float [20];
    • C、char[] ca= “Some String”;
    • D、int ia [][]= {4,5,6} {1,2,3};

    正确答案:A

  • 第17题:

    下面哪些语句能够正确地生成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

  • 第18题:

    下列语句创建了多少个string对象?() string[,]strArray=new string[3][4];

    • A、0
    • B、3
    • C、4
    • D、12

    正确答案:D

  • 第19题:

    String s=new String("xyz");创建了几个String Object?


    正确答案: 两个或一个,”xyz”对应一个对象,这个对象放在字符串常量缓冲区,常量”xyz”不管出现多少遍,都是缓冲区中的那一个。New String每写一遍,就创建一个新的对象,它一句那个常量”xyz”对象的内容来创建出一个新String对象。如果以前就用过’xyz’,这句代表就不会创建”xyz”自己了,直接从缓冲区拿。

  • 第20题:

    11. String test = “This is a test”;  12. String[] tokens = test.split(”/s”);  13. System.out.println(tokens.length);  What is the result?() 

    • A、 0
    • B、 1
    • C、 4
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:D

  • 第21题:

    import java.util.*;  public class WrappedString {  private String s;  public WrappedString(String s) { this.s = s; }  public static void main(String[] args) {  HashSet hs = new HashSet();  WrappedString ws1 = new WrappedString(”aardvark”);  WrappedString ws2 = new WrappedString(”aardvark”);  String s1 = new String(”aardvark”);  String s2 = new String(”aardvark”);  hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2);  System.out.println(hs.size()); } }  What is the result?() 

    • A、 0
    • B、 1
    • C、 2
    • D、 3
    • E、 4
    • F、 Compilation fails.
    • G、 An exception is thrown at runtime.

    正确答案:D

  • 第22题:

    单选题
    import java.util.*;  public class WrappedString {  private String s;  public WrappedString(String s) { this.s = s; }  public static void main(String[] args) {  HashSet hs = new HashSet();  WrappedString ws1 = new WrappedString(”aardvark”);  WrappedString ws2 = new WrappedString(”aardvark”);  String s1 = new String(”aardvark”);  String s2 = new String(”aardvark”);  hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2);  System.out.println(hs.size()); } }  What is the result?()
    A

     0

    B

     1

    C

     2

    D

     3

    E

     4

    F

     Compilation fails.

    G

     An exception is thrown at runtime.


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

  • 第23题:

    单选题
    下列语句创建了多少个string对象()。string[,]strArray=new string[3][4];
    A

    0

    B

    3

    C

    4

    D

    12


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

  • 第24题:

    单选题
    下面关于数组声明和初始化的语句哪个有语法错误()
    A

    int a1[]={3,4,5};

    B

    String a2[]={string1,string1,string1};

    C

    String a3[]=new String(3);

    D

    int[][] a4=new int[3][3];


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