1:package MyPackage; public class MyRectangle { int width; int height; public MyRectangle() { width = 10; height = 20; }public int area(int width,int height) { int area = width * height; return area; } public static void main(String[] args){ MyRectangle mr=new MyRectangle(); System.out.println("矩形面积为:"+mr.area(46, 60)); } }2. public class Test { public int mol(int i){ return i*i; } public int mol(int i,int j){ return i*j; } public void mol(String str){ System.out.println("Hello,"+str+"!"); } public static void main(String[] args){ Test t=new Test(); System.out.println("128的平方等于"+t.mol(128)); System.out.println("12*8="+t.mol(12,8)); t.mol("teacher"); } }