1.
package q; public class point { int x; int y; public point(int x0, int y0) { super(); this.x = x0; this.y = y0; } public point() { super(); } public String movePoint(int dx, int dy) { x = x + dx; y = y + dy; return("x是"+x+",y是"+y); } public static void main(String[] args) { point p1 = new point(1, 2); point p2 = new point(3, 4); System.out.println(p1.movePoint(1, 2)); System.out.println(p2.movePoint(3, 4)); } }
2.
package q; public class Rectangle { int length; int width; public int getArea(int length,int width){ return length*width; } public int getPer(int length,int width){ return (length+width)*2; } public void showAll(){ System.out.println("矩形的长是"+length+"矩形的宽是"+width+"周长是"+(length+width)*2+"面积是"+length*width); } public Rectangle(int length, int width) { super(); this.length = length; this.width = width; } public static void main(String[] args) { // TODO Auto-generated method stub Rectangle r=new Rectangle(3, 6); r.showAll(); } }
3.
package q; public class test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub computer c=new computer(); c.coulour='蓝'; c.cpu=133; c.show(); computer c1=new computer('黄',333); c1.show(); } }
package q; public class test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub computer c=new computer(); c.coulour='蓝'; c.cpu=133; c.show(); computer c1=new computer('黄',333); c1.show(); } }
package q;
public class Rectangle { int length; int width; public int getArea(int length,int width){ return length*width; } public int getPer(int length,int width){ return (length+width)*2; } public void showAll(){ System.out.println("矩形的长是"+length+"矩形的宽是"+width+"周长是"+(length+width)*2+"面积是"+length*width); } public Rectangle(int length, int width) { super(); this.length = length; this.width = width; } public static void main(String[] args) { // TODO Auto-generated method stub Rectangle r=new Rectangle(3, 6); r.showAll(); }}