1.
package test; public class LH { int cpu; char color; public void all() { System.out.println("颜色是" + color); System.out.println("cpu是" + cpu); } }
package test; public class LH { public static void main(String[] args) { book p1 = new book(); p1.color='red'; p1.cpu=0; p1.com(); } }
2.
package test; public class Person { String name; double sg; int nl; public void sayHallo(){ System.out.println("hello,my name is "+name); System.out.println("我的身高为"+sg); System.out.println("我的年龄为"+nl); } }
package test; public class PersonCreate { public static void main(String[] args) { Person p1=new Person(); p1.name="zhangsan"; p1.nl=33; p1.sg=1.73; p1.sayHallo(); Person p2=new Person(); p2.name="lishi"; p2.nl=44; p2.sg=1.74; p2.sayHallo(); } }