
正文
填空题java源代码,java程序编程填空题及答案
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java程序填空题!!!设计一个学生类Student,其属性有name(姓名)、age(年龄)和degree(学位)。
class Student{
private String name;
private int age;
private String degree;
public Student(String name, int age, String degree) {
super();
this.name = name;
this.age = age;
this.degree = degree;
}
public Student() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getDegree() {
return degree;
}
public void setDegree(String degree) {
this.degree = degree;
}
public void show(){
System.out.println("姓名:" + this.getName() + ". 年龄:" + this.getAge() + ". 学位:" + this.getDegree() );
}
}
class Undergraduate extends Student{
private String specialty;
public String getSpecialty() {
return specialty;
}
public void setSpecialty(String specialty) {
this.specialty = specialty;
}
public Undergraduate(String name, int age, String degree, String specialty) {
super(name, age, degree);
this.specialty = specialty;
}
public Undergraduate(String name, int age, String degree) {
super(name, age, degree);
}
public void show(){
System.out.println("姓名:" + this.getName() + ". 年龄:" + this.getAge() + ". 学位:" + this.getDegree() + ". 专业:" + this.getSpecialty());
}
}
class Graduate extends Student{
private String direction;
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
public Graduate(String name, int age, String degree, String direction) {
super(name, age, degree);
this.direction = direction;
}
public Graduate(String name, int age, String degree) {
super(name, age, degree);
}
public void show(){
System.out.println("姓名:" + this.getName() + ". 年龄:" + this.getAge() + ". 学位:" + this.getDegree() + ". 研究方向:" + this.getDirection());
}
}
public class exp1401 {
public static void main(String[] args) {
Undergraduate stu1=new Undergraduate("张三",23,"本科","工业自动化");
Graduate stu2=new Graduate("李四",27,"硕士","网络技术");
stu1.show();
stu2.show();
}
}
相关问答
Q1: JAVA填空题
1.对象
6.java命令加上的java源文件 3个字节码文件
7,重写 重载、
10.GridLayout
三。
1.文件名为 A.java
2. x str
3.n%k == 0
Q2: java程序填空题?
public class Main {
public static void main(String[] args) {
Test test = new Test(true);
}
}
class Test {
public Test(){
System.out.println("Constructor one invoked!");
}
public Test(int x){
//此处添加代码
Test();
System.out.println("Constructor two invoked!");
}
public Test(boolean b){
//此处添加代码
Test(1);
System.out.println("Constructor three invoked!");
}
}






