1.例11.1继承学生类
import java.util.Scanner; import java.util.*; public class Cjava { public static void main(String[]args) { Student1 s1=new Student1(); s1.get_value(); s1.get_value1(); s1.display(); s1.display_1(); } } class Student{ private int num;private String name;private char sex; public void get_value() { Scanner s=new Scanner(System.in); num=s.nextInt(); String s2; s2=s.next(); sex=s2.charAt(0); Scanner s3=new Scanner(System.in); name=s3.nextLine(); } public void display() { System.out.println("num:"+num); System.out.println("name:"+name); System.out.println("sex:"+sex); } } class Student1 extends Student{ private int age;private String addr; public void display_1() { System.out.println("age:"+age); System.out.println("address:"+addr); } public void get_value1() { age=19;addr="shandong"; } }
2.写题过程中输入字符和字符串出现了问题,发现定义一个Scanner后输入不同的字符串需要再定义。
3.明天继续写例题