标签:
1 class BirthDate { 2 private int day; 3 private int month; 4 private int year; 5 6 public BirthDate(int d, int m, int y) { 7 day = d; 8 month = m; 9 year = y; 10 } 11 12 public void setDay(int d) { 13 day = d; 14 } 15 16 public void setMonth(int m) { 17 month = m; 18 } 19 20 public void setYear(int y) { 21 year = y; 22 } 23 24 public int getDay() { 25 return day; 26 } 27 28 public int getMonth() { 29 return month; 30 } 31 32 public int getYear() { 33 return year; 34 } 35 36 public void display() { 37 System.out.println 38 (day + " - " + month + " - " + year); 39 } 40 } 41 42 43 public class Test1{ 44 public static void main(String args[]){ 45 Test1 test = new Test1(); 46 int date = 9; 47 BirthDate d1= new BirthDate(7,7,1970); 48 BirthDate d2= new BirthDate(1,1,2000); 49 test.change1(date); 50 test.change2(d1); 51 test.change3(d2); 52 System.out.println("date=" + date); 53 d1.display(); 54 d2.display(); 55 } 56 57 public void change1(int i){ 58 i = 1234; 59 } 60 61 public void change2(BirthDate b) { 62 b = new BirthDate(22,2,2004); 63 } 64 65 public void change3(BirthDate b) { 66 b.setDay(22); 67 } 68 }
答案是:
---------------
date = 9
7-7-1970
22-1-2000
----------------
1 class Point { 2 double x,y,z; 3 4 Point(double _x,double _y,double _z) { 5 x = _x; 6 y = _y; 7 z = _z; 8 } 9 10 void setX(double _x){ 11 x = _x; 12 } 13 14 void setY(double _y){ 15 y = _y; 16 } 17 18 void setZ(double _z){ 19 z = _z; 20 } 21 22 double getInstance(Point p){ 23 return (x -p.x) * (x -p.x) + (y -p.y) * (y -p.y) + (z -p.z) * (z -p.z); 24 } 25 } 26 27 28 public class TestPoint{ 29 public static void main(String[] args){ 30 Point p = new Point(1.0,2.0,3.0); 31 p.setX(2); 32 p.setY(3); 33 p.setZ(4); 34 System.out.println(p.x); 35 System.out.println(p.y); 36 System.out.println(p.z); 37 38 System.out.println(p.getInstance(new Point(1.0,1.0,1.0))); 39 } 40 }
标签:
原文地址:http://www.cnblogs.com/roger-h/p/4426364.html