1、java 程序设计 编程 实例 大全 深入 一public class FloatTestpublic static void main(String args)float f=1.2f;float s=1.3F;float t=(float)1.4;System.out.println(f+“n“+s+“n“+t);public class ReturnTestpublic static void main(String args)ReturnTest rt=new ReturnTest();rt.method(2);/ return;public void method(int a)if(
2、a3) System.out.println(+a);System.out.println(+a);public class ReferenceTestint a=4;public static void main(String args)ReferenceTest rt1=new ReferenceTest();ReferenceTest rt2=new ReferenceTest();rt1.a=5;System.out.println(rt1.a+“n“+rt2.a);rt2=rt1;rt1.a=5;System.out.println(rt1.a+“n“+rt2.a);public c
3、lass Peopleint age;public void change1(int i)i+;public void change2(People p)p=new People();p.age+;public void change3(People p,int i)p.age+;i+;public static void main(String args)People people=new People();int a=0;/*people.change1(people.age);System.out.println(people.age);*/*people.change2(people.
4、age);System.out.println(people.age);*/people.change3(people,people.age);System.out.println(people.age);public class Child extends Parentpublic Child()super(1);System.out.println(“Child“);public static void main(String args)Child child=new Child();class Parentpublic Parent(int i)System.out.println(“p
5、arent1“);public Parent()System.out.println(“parent2“);public class ParamTestpublic void changePoint(Point point)/ Point point=new Point();point.x=3;point.y=4; public static void main(String args)ParamTest pt=new ParamTest();Point point=new Point();pt.changePoint(point);System.out.println(point.x+“n“
6、+point.y);class Pointint x;int y;public class ParamTest2public static void main(String args)C c=new C();int a=1;c.changeInt(a);System.out.println(a);class Cvoid changeInt(int a)a+;public class ParamTest3public void change(Person person1,Person person2)person1.name=“li si“;person2.name=“wang wu“;publ
7、ic static void main(String args)Person person1=new Person();person1.name=“zhang san“;Person person2=new Person();/Person person2=person1;ParamTest3 test=new ParamTest3();test.change(person1,person2);System.out.println(person1.name+“n“+person2.name);class PersonString name;public class OverloadTestpu
8、blic int add(int a,int b)return a+b;public int add(int a,int b,int c)return a+b+c;public static void main(String args)OverloadTest test=new OverloadTest();int r1=test.add(1,2);int r2=test.add(1,2,3);System.out.println(r1+“n“+r2);public class OverloadTest2public int method(int a,int b)System.out.prin
9、tln(a+b);return 1; public boolean method(int a)System.out.println(a);return false;public static void main(String args)OverloadTest2 test=new OverloadTest2();int result1 = test.method(1,2);boolean result2 = test.method(3);public class ConstructorOverloadpublic ConstructorOverload()this(3);System.out.println(“test“);public ConstructorOverload(int i)System.out.println(+i);public static void main(String args)ConstructorOverload col1=new ConstructorOverload();ConstructorOverload col2=new ConstructorOverload(2);public class ConstructorTest