【JAVA 小结】Java关于类与对象的代码

分别建立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");
	 }
 
}

 

posted @ 2015-10-10 14:59  zhaocundang  阅读(360)  评论(0编辑  收藏  举报