java乱码
运行环境是:eclipse
class Person {
private String name;
private char sex;
private int age;
protected String getName() {
return name;
}
protected char getSex() {
return sex;
}
protected int getAge() {
return age;
}
public Person(String name,char sex,int age){
this.name =name;
this.age=age;
this.sex=sex;
}
public void think(){
System.out.println(name +"在思考^^^^^^");
}
}
class xueshenglei extends Person {
private String xuehao;
public xueshenglei(String name,char sex,int age,String xuehao) {
super(name,sex,age);
this.xuehao=xuehao;
}
protected String getXuehao() {
return xuehao;
}
public void learn() {
System.out.println(getName()+"正在在学习………………");
}
}
class daxueshenglei extends xueshenglei{
public daxueshenglei(String name,char sex,int age,String xuehao){
super(name,sex,age,xuehao);
}
public void study() {
System.out.println(getName()+"正在学习^^^^^^");
}
public String fun(){
return String.format("所构造的大学生信息:%s,%c,%d岁,%s号" ,getName(),getSex(),getAge(),getXuehao());
}
}
public class ceshi3 {
public static void main(String[] args) {
System.out.println("======构造大学生的对象======");
Scanner scan =new Scanner(System.in);
String xuehao=null,name=null;
int age=0;
char sex=0;
while(true){
System.out.println("请输入空格分隔的姓名 、性别 、年龄 、学号 \n");
try {
name=scan.next();
if (name.equals("end")) {
System.out.println("程序结束————————");
}
sex=scan.next().charAt(0);
age=scan.nextInt();
xuehao = scan.next();
if (xuehao.equals("end")) {
System.out.println("程序结束————————");
}
}
catch (Exception e)
{
System.out.println("异常:"+e);
}
daxueshenglei yi =new daxueshenglei(name,sex,age,xuehao);
System.out.println(yi.fun());
yi.learn();
yi.study();
}
}
}
结果截图: