一道Java题目,关于使用Super语句的,有人会吗求助
4个回答
展开全部
/** * @author 2015 班级类 */public class SchoolClass { private String cno;// 班级号 private String name;// 班级名称 public String getCno() { return cno; } public void setCno(String cno) { this.cno = cno; } public String getName() { return name; } public void setName(String name) { this.name = name; } protected SchoolClass(String cno, String name) { super(); this.cno = cno; this.name = name; } protected SchoolClass() { super(); } /** * 班级信息 */ public void showInfo() { System.out.println("班级号:" + cno + " 班级名称:" + name); }}
/** * @author 2015 学生 */public class Stu extends SchoolClass { private String sno; private String sname; protected Stu(String cno, String cname, String sno, String sname) { super(cno, cname); this.sno = sno; this.sname = sname; } public void showInfo() { System.out.println("姓名:" + sname+" 班级号:" + getCno() + " 班级名称:" + getName()); } public static void main(String[] args) {// 学生的信息 :计算机01班、s001、张三 Stu stu = new Stu("s001", "计算机01班", "001", "张三"); stu.showInfo(); }}
/** * @author 2015 学生 */public class Stu extends SchoolClass { private String sno; private String sname; protected Stu(String cno, String cname, String sno, String sname) { super(cno, cname); this.sno = sno; this.sname = sname; } public void showInfo() { System.out.println("姓名:" + sname+" 班级号:" + getCno() + " 班级名称:" + getName()); } public static void main(String[] args) {// 学生的信息 :计算机01班、s001、张三 Stu stu = new Stu("s001", "计算机01班", "001", "张三"); stu.showInfo(); }}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package test1;
public class SchoolClass {
private String no;
private String name;
public SchoolClass(){
}
public SchoolClass(String No,String Name){
no = No;
name = Name;
}
public String getNo() {
return no;
}
public String getName() {
return name;
}
public void showInfo(){
System.out.println("班级号:\t"+this.getNo());
System.out.println("班级名称:\t"+this.getName());
}
}
package test1;
public class Student extends SchoolClass {
private String sno;
private String sname;
public Student(){
}
public Student(String sNo,String sName,String No,String name){
super(No,name);
sno = sNo;
sname = sName;
}
public String getSno() {
return sno;
}
public String getsName() {
return sname;
}
@Override
public void showInfo() {
// TODO 自动生成的方法存根
System.out.println("班级:\t"+super.getName());
System.out.println("学号:\t"+this.getSno());
System.out.println("姓名:\t"+this.getsName());
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Student s = new Student("s001","张三","001","计算机一班");
s.showInfo();
}
}
public class SchoolClass {
private String no;
private String name;
public SchoolClass(){
}
public SchoolClass(String No,String Name){
no = No;
name = Name;
}
public String getNo() {
return no;
}
public String getName() {
return name;
}
public void showInfo(){
System.out.println("班级号:\t"+this.getNo());
System.out.println("班级名称:\t"+this.getName());
}
}
package test1;
public class Student extends SchoolClass {
private String sno;
private String sname;
public Student(){
}
public Student(String sNo,String sName,String No,String name){
super(No,name);
sno = sNo;
sname = sName;
}
public String getSno() {
return sno;
}
public String getsName() {
return sname;
}
@Override
public void showInfo() {
// TODO 自动生成的方法存根
System.out.println("班级:\t"+super.getName());
System.out.println("学号:\t"+this.getSno());
System.out.println("姓名:\t"+this.getsName());
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Student s = new Student("s001","张三","001","计算机一班");
s.showInfo();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package test;
public class SchoolClass {
private String cno;
private String name;
public SchoolClass(String cno, String name) {
super();
this.cno = cno;
this.name = name;
}
public String getCno() {
return cno;
}
public void setCno(String cno) {
this.cno = cno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String showInfo() {
return "SchoolClass [cno=" + cno + ", name=" + name + "]";
}
}
public class SchoolClass {
private String cno;
private String name;
public SchoolClass(String cno, String name) {
super();
this.cno = cno;
this.name = name;
}
public String getCno() {
return cno;
}
public void setCno(String cno) {
this.cno = cno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String showInfo() {
return "SchoolClass [cno=" + cno + ", name=" + name + "]";
}
}
更多追问追答
追问
请问这个没有student类吗
追答
public class Student extends SchoolClass {
private String sno;
private String name;
public Student(String cno, String cname, String sno, String sname) {
super(cno, cname);
this.sno = sno;
name = sname;
}
@Override
public String showInfo() {
return super.showInfo() + "Student [sno=" + sno + ", name=" + this.name
+ "]";
}
public static void main(String[] args) {
System.out.println(new Student("1", "计算机一班", "s001", "张山").showInfo());
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
都这么久了,面试早该结束了,还需要回答么?
更多追问追答
追问
我又不是面试的,刚开始学而已啊
追答
好吧,帮你写写,但你得等我,然后给分啊。10分钟
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询