已知下列接口和抽象类:interface Tool{int add(int x,int y);//返回参数和int max(int x,int y);//返回参数最大值}abstract Person{abstract String setName(String name);//设置姓名}要求:定义一个类class Student{…},继承Person类,实现Tool接口。
举一反三
- 设有下面两个类的定义: class Person {} class Student extends Person { long id; // 身份证号 int score; // 入学总分 String name; // 姓名 int getScore(){return score;} } 问:类Person和类Student的关系是
- 以下的类(接口)定义中正确的是( ) A: public class A{ private int x; public getX(){ return x; }} B: public abstract class A{ private int x; public abstract int getX(); public int aMethod(){ return 0; }} C: public class A{ private int x; public abstract int getX();} D: public interface interfaceA{ private int x; public int getX(){ return x; }}
- (6-2)定义如下Person类,(1)处合理的代码是。 class Person { String name, department; int age; public Person(String n) { name = n; } public Person(String n, int a) { name = n; age = a; } public Person(String n, int a, String d) { ① department = d; } }
- 在C#中,下列结构或者类定义正确的是(选一项) A: public struct Person{ string name; int age; public void ShowName(){ Console.WriteLine(name); }} B: public struct Person{ string name; int age; public Person(){ Conssole.WriteLine(name); }} C: public class Person{ string name; int age; public Person(){ Conssole.WriteLine(name); }} D: public class Person{ string name; int age; public Person(string name){ Conssole.WriteLine(name); }}
- 【多选题】给出如下代码 //接口 public interface Info { String show(int m, int n); } //类 public abstract class implements Info{ —————————— } 问:在类划线处,下列哪些定义是合法的?() A. public String show(int m, int n) {} B. public void show(int m, int n) {} C. protected String show(int m, int n) {} D. public Object show(int m,int n) {} E. public abstract String show(int m, int n); F. 其他定义都不合法