1. package er; public class point { int x; int y; point() { } point(int dx,int dy) { x+=dx; y+=dy; } void movepoint(int p1,int p2) { p1=x*2; p2=y*2; System.out.println("p1的坐标为"+p1+" "+"p2的坐标为"+p2); } } package er; public class person { public static void main(String[] args) { point p=new point(); p.x=6; p.y=2; p.movepoint(p.x,p.y); } }
2.
package er; public class point { int length; int width; point(int width, int length) { this.width = width; this.length = length; } void getArea() { System.err.println("面积:"+width*length); } void getPer() { System.out.println("周长:"+(width+length)*2); } void showAll() { System.out.println("长:"+length+" 宽:"+width); } public static void main(String[] args) { point a = new point(2, 5); a.getArea(); a.getPer(); a.showAll(); } }
3.
package er; public class point { char color; int cpu; point() { } point(char color, int cpu) { this.color = color; this.cpu = cpu; } void point() { System.out.println("颜色:"+color); System.out.println( "型号:"+cpu); } public static void main(String[] args) { point p= new point('p',4689); p.point(); } }
4.
package test; public class person { String name; double height; int age; public void sayHello(){ System.out.println("hello,my name is " + this.name ); } public void Value(String name, int age, double height){ this.name = name; this.age = age; this.height = height; } } package test; public class personcreate { public static void main(String[] args) { // TODO Auto-generated method stub person p1 = new person(); p1.Value("zhangsan",33,1.74); p1.sayHello(); person p2 = new person(); p2.Value("lishi",44,1.74); p2.sayHello(); } }