java写一个关于人,教师,学生的类。要求定义静态数据域,用继承方法写。最后编写一个主类来测试这三个类
3个回答
展开全部
public class test {
public static void main(String[] args) {
System.out.println(new Person("p"));
System.out.println(new Teacher("t","教书"));
System.out.println(new Student("s","学习"));
}
}
class Person{
public static String name;
Person(){ }
Person(String name){
setName(name);
}
public String getName() {
return name;
}
public void setName(String name) {
Person.name = name;
}
public String toString(){
return getName();
}
}
class Teacher extends Person{
public static String action ;
Teacher(String name,String action) {
this.setName(name);
this.setAction(action);
}
public static String getAction() {
return action;
}
public static void setAction(String action) {
Teacher.action = action;
}
public String toString(){
return getName()+getAction();
}
}
class Student extends Person{
public static String action ;
Student(String name,String action) {
this.setName(name);
this.setAction(action);
}
public static String getAction() {
return action;
}
public static void setAction(String action) {
Student.action = action;
}
public String toString(){
return getName()+getAction();
}
}
public static void main(String[] args) {
System.out.println(new Person("p"));
System.out.println(new Teacher("t","教书"));
System.out.println(new Student("s","学习"));
}
}
class Person{
public static String name;
Person(){ }
Person(String name){
setName(name);
}
public String getName() {
return name;
}
public void setName(String name) {
Person.name = name;
}
public String toString(){
return getName();
}
}
class Teacher extends Person{
public static String action ;
Teacher(String name,String action) {
this.setName(name);
this.setAction(action);
}
public static String getAction() {
return action;
}
public static void setAction(String action) {
Teacher.action = action;
}
public String toString(){
return getName()+getAction();
}
}
class Student extends Person{
public static String action ;
Student(String name,String action) {
this.setName(name);
this.setAction(action);
}
public static String getAction() {
return action;
}
public static void setAction(String action) {
Student.action = action;
}
public String toString(){
return getName()+getAction();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Test {
public static void main(String args[]){
System.out.println(Person.className);
System.out.println(Teacher.className);
System.out.println(Student.className);
}
}
class Person{
public static String className = "人类";
}
class Teacher extends Person{
public static String className = "老师";
}
class Student extends Person{
public static String className = "学生";
}
public static void main(String args[]){
System.out.println(Person.className);
System.out.println(Teacher.className);
System.out.println(Student.className);
}
}
class Person{
public static String className = "人类";
}
class Teacher extends Person{
public static String className = "老师";
}
class Student extends Person{
public static String className = "学生";
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
..这种简单的入门题...还是可以自己想出来的..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询