分别建立2个类class works 和 Person import java.io.*; public class works { public static void main(String[] args) { Person ZhangSan= new Person(); InputStreamReader stdin = new InputStreamReader(System.in); BufferedReader bufin = new BufferedReader(stdin); try{ System.out.println("please Input his Name"); ZhangSan.Name = bufin.readLine(); System.out.println("please Input his Age"); ZhangSan.Age = bufin.readLine(); ZhangSan.talk(); } catch(Exception e) { System.err.println("error"); } } }
public class Person { String Name; String Age; void talk() { System.out.println("I‘m "+Name+", I‘m "+Age+",year old"); } }
时间: 2024-09-28 17:27:49