首页/ 题库 / [单选题]给出下面不完整的类代码,则横线处的语句应的答案

给出下面不完整的类代码,则横线处的语句应该为( )。 class Person { String name,department; int age; public Person (Strings) {name=s;} public Person (String s,int

单选题
2022-06-21 13:34
A、{name=s;age=a;} public Person (String n,String d,intA){ __________ department=d; } }A)Person (n,A);
B、this (Person(n,A));
C、this(n,A);
D、this(name,age);
查看答案

正确答案
C

试题解析
解析:本题主要考查在同一个类的不同构造方法中调用该类的其他构造方法需要使用 this(…)的形式,而且必须是在构造方法的第一行调用。这个和普通方法重载调用的方式不同,普通方法可以直接使用方法名加参数来调用,而且调用位置没有限制,因此选项A是不行的,选项B的语法就是错误的,选项D的错误在于在父类型的构造方法被调用前不能引用类的成员。构造方法是一个类对象实例化的开始,因此在构造方法中不能将成员作为参数引用。

标签:
感兴趣题目
能将程序补充完整的选项是 class Person { private int a; public int change(int m){return m;} } public class Teacher extends Person { public int b; public static void main(String arg[]) { Person p=new Person(); Teacher t=new Teacher(); int i; _____ } }
能将程序补充完整的选项是______。 class Person{ private int a; phblic int change(int m){return m;} } public class Teacher extends Person{ public int b; public static void main(String arg[ ]){ Person p=new Person( ); Teacher t=new Teacher( ); int i; ______; } }
下面指令序列测试BH中的数是否为奇数,若为奇数则转移至K1处,横线处的指令应为( ) TEST BH,01H ______K1
以下程序输出结果为( )。 class test 2 { public static void main(String args[]) { int n = 7; n<<=3; n=n&n+1|1n+2^n+3; n>>=2; System.out.println(n); } }
下面程序段的输出结果是 public class Test{ public static void main(String args[]){ int n=5,sum=0; while(n>0){ sum+=n; --n; } System.out.println("sum is"+sum); } }
下面程序段的输出结果是 public class Test{ public static void main(String args[]){ int n=5,sum=O; while(n>0){ sum+=n; --n; } System.out.println("sum is "+Sum); } }
在下列程序的划线处应填入的语句是class Person { private int a;}public class Man extends Person{ public int b; public static void main (String arg []){ Person p=new Person(); Man t=new Man(); int i: }}
在下列程序的划线处应填入的语句是 ( ) class Person { private int a; } public class Man extends Person { public int b public static void main(String arg[]) { Person P=new Person(); Man t=new Man(); int i; ______ } }
给出下面不完整的类代码,则横线处的语句应该为( )。 class Person { String name,department; int age; public Person (Strings) {name=s;} public Person (String s,int
已知在“通用”代码有以下语句: Dim stu()As String 则,在某一事件代码中使用()是正确的。
设有以下语句: struct SS { int no; char name[10];}PERSON; 则下面叙述中错误的是 ( )
在下列程序的划线处应填入的语句是 class Pemon { pnvate int a; } public class Man extends Person { public int b; public static void main(String arg[ ] ) { Person p = new Person( ); Man t = new Man( ); int i; ________ } }
相关题目
下面这段代码会产生( )个String对象。 String s1 = "hello"; String s2 = s1.substring( 3); String s3 = s1.toString(); String s4 = new StringBuffer(s1).toString();
给出下面代码,关于该程序以下哪个说法是正确的? ( )public class Person(){static int arr[] = new int[5];public static void main(String a[]){System.out.println(arr[0]); }}
下列语句序列执行后,k的值是( )。 public class Test{ public static void main (String[] args) { int m=3,n=6,k=0; while ((m++) <(n--)) ++k; System. out. println (k); } }
下面程序段的输出结果是( )。 public class Test { public static void main (String[] args) { int n=10; do { System.out.println("n is"+n); }while(--n>10); } }
下列代码段中声明了3个类: Class Person{}; Class Student:publiC Person{}; Class Undergraduate:Student{}; 下列关于这些类之间关系的描述中,错误的是( )。
下列代码段声明了3个类:class Person();class Student:public Person{};class Undergraduate:Student{};下列关于这些类之间关系的描述中,错误的是( )。

已知在“通用”代码有以下语句:
Dim stu()As String
则,在某一事件代码中使用()是正确的。

给出下面代码,关于该程序以下哪个说法是正确的?( ) public class Person{ static int arr[] = new int[5]; public static void main(String a[]) { System.out.println(arr[0]); } }
 下面指令序列测试 BH 中的数是否为奇数, 若为奇数则转移至 K1 处,横线处的指令应为(    )。TEST BH,01H_____K1  
24下面指令序列测试BH中的数是否为奇数,若为奇数则转移至K1处,横线处的指令应为()。TEST BH,01H_____K1
在声明派生类时,如果不显示地给出继承方式,缺省的类继承方式是私有继承private。已知有如下类定义: class TestClass{ protected: void fun(){} }; class TestClass1:TestClass{}; 则TestClass类中的成员函数fun(),TestClass1类中的访问权限是( )。
下面这段代码会产生( )个String对象。
设有下列两个类的定义,则类Person和类Man的关系是 class Person { long id;/ / 身份证号 String name;/ / 姓名 } class Man extends Person { int age;/ / 年龄 int getScore( ) { return score; } }
设有下列两个类的定义,则类Person和类Man的关系是( )。 class Person { long id; //身份证号 String name; //姓名 } class Man extends Person { int age; //年龄 int getAge() { return age; } }
设有下列两个类的定义,则类Person和类Man的关系是 ( ) class Person { long id; //身份证号 String name; //姓名 } class Man extends Person{ int age;//年龄 int getScore() { return score; } }
设有以下函数过程Private Function Fun(a()As Integer,b As String)As IntegerEhd Function若已有变量声明:Dim x(5)As Integer,n As Integer,ch As String则下面正确的过程凋用语句是
关于下面语句的说法正确的是 String[][]s=new String[10][];
关于下面语句的说法正确的是( )。 String[][] s=new String[10][];
下列语句输出结果为( )。 public class test { public static void main (String args[]) { String s1=new String("How"); String s2=new String("How"); System.out.println(!(s1.equals(s2))); } }
能将程序补充完整的选项是 class Person { private int a; public int change(int m){return m; } } public class Teacher extends Person { public int b; public static void main(String arg[]) { Person p=new Person(); Teacher t=new Teacher(); int i; ______ } }
广告位招租WX:84302438

免费的网站请分享给朋友吧