已知类名为Student,下面构造方法定义的有哪些?
A: Student( )
B: Student(String name)
C: void student()
D: void input()
A: Student( )
B: Student(String name)
C: void student()
D: void input()
举一反三
- Student类中存在String类型name属性,下列Student类的构造方法中,哪个是正确的? A: Student(String name){} B: Student(String name) C: Student(name)() D: NewStudent (String name){}
- 【填空题】阅读程序写结果 public class Student { private static int sid = 0; private String name; int id; Student(String name) { this.name = name; id = sid++; } public void info() { System.out.println("My name is "+name+" No."+id); } public static void infoSta() { System.out.println(sid); } public static void main(String arg[]) { Student.sid = 100; Student st1 = new Student("huahua"); st1.sid = 2000; Student st2 = new Student("meimei"); st1.info(); st2.info(); } }
- 下面程序运行的结果是 struct Student { public int age; public string name; public Student(int age, string name) { this.age = age; this.name = name; } } class Program { static void Main(string[] args) { Student stu1 = new Student(18, "小方"); Student stu2 = new Student(24, "小刚"); stu2 = stu1; stu1.age = 30; stu1.name = "小燕"; Console.WriteLine("{1},{0}",stu2.age,stu2.name); } }
- 如果名为Student的类没有显式定义构造函数,则隐式提供以下构造函数。 A: public Student() B: protected Student() C: private Student() D: Student()
- 有一个Student类,下面是该类无参构造方法的定义public Student(){}