- 博客(20)
- 收藏
- 关注
原创 this调用构造方法那必须放在构造方法中的第一条语句
public class ThisQuoteTest{ String name; int age; String work; public ThisQuoteTest() { this("Lily",23,"teacher"); } public ThisQuoteTest(String name,int age,String work) { this.name =nam
2014-01-09 16:32:43 5494
原创 注意this用法,以及当用static 修饰属性时,无论生成多少个对象,其共同拥有一个属性,不再各自拥有自己的属性
public class ThisTest{ static int age; static String name; public void make(String name,int age) { this.name=name; this.age =age; } public static void main(String args[]) { ThisTest str=
2014-01-09 15:51:56 437
原创 equals方法及对其进行重写
public class EqualsTest{ int age; String name; public static void main(String args[]) { EqualsTest test=new EqualsTest(); EqualsTest test2=new EqualsTest(); System.out.println(test.equals(t
2014-01-09 11:31:03 397
原创 将引用做为传递参数
public class QuoteTest{ int age; String name; public void make(QuoteTest quo) { quo.name="Lucy"; } public static void main(String args[]) { QuoteTest test=new QuoteTest(); test.name="Lil
2014-01-09 10:23:47 449
原创 返回数组类型
public class ReturnArrayTest{ static int [][]array={{1,3,5,7},{2,4,6},{7,3,8,4,9}}; static int[][] method(int [][]array) { for(int i=0;i<array.length;i++) { for(int j=0;j<array[i].length;j+
2014-01-09 10:01:07 573
原创 二维数组的传递及打印输出
public class DoubleArrayTest{ static String array[][]={{"China","Chinese"},{"Love","Like"},{"Lucy","Lily"}}; static void make(String[][] array) { for(int i=0;i<array.length;i++) { for(int
2014-01-09 09:32:47 577
原创 将数组作为参数进行传递
public class ArristTest{ int []array={1,3,5,7,9,2,4,6,8,10}; public int comp(int []array) { int max=array[0]; for(int i=0;i<array.length;i++) { if(array[i]>max) max=array[i]; } re
2014-01-08 16:38:53 585
原创 内部类的相关特性
public class InnerClass{ public static void main(String args[]) { Outer tr=new Outer(); tr.jump(); System.out.println("My name is: "+tr.str+", I am "+tr.age); }}class Outer{ String str;
2014-01-08 11:51:29 373
原创 Object类中toString方法
/*public class ToStringMethod{ String str; int age; public static void main(String args[]) { ToStringMethod train=new ToStringMethod(); System.out.println(train); }}*/public class ToString
2014-01-08 11:16:56 474
原创 抽象类的继承与方法实现
public class AbstractTrain extends InformationB{ void boss(String str,int age,String str1) { this.str=str; this.age=age; this.str1=str1; System.out.println("干部--->姓名: "+this.str+",年龄: "+thi
2014-01-08 10:33:30 731
原创 类是单继承的,但是接口是可以多继承的
public class InterfaceExtends implements C{ public void person (String str) { System.out.println("This Person is :"+str+"!"); } public void student (String str) { System.out.println("This St
2014-01-08 09:56:59 638
原创 抽象类与抽象方法
public class TestAbstractDemo1{ public static void main(String args[]) { Student s=new Student("张三",20,"学生"); Worker w=new Worker("李四",30,"工人"); System.out.println(s.talk()); System.out.pri
2014-01-06 17:09:18 400
原创 方法重写和重载
public class Java10_2 extends Person{ public Java10_2() { System.out.println("My name is "+this.name+" I am "+this.age+" years old"+" and I like "+this.like); } public Java10_2(String str,int i
2014-01-06 11:46:42 364
原创 子类重写父类的方法,用super调用父类中的原方法
public class Java10_1 extends Student { public void meth() { System.out.println("我是子类"); super.meth(); } public Java10_1() { } public static void main(String args[]) { Java10_1 j
2014-01-06 11:16:42 2244
原创 子类中方法与父类中形成重写关系,可以在构造方法中用super来调用父类中的该方法
public class ReloadTest extends Reload{ void write (int x) { this.age=x/2; } public ReloadTest() { super.write(10); } public static void main(String args[]) { ReloadTest rew=new ReloadT
2014-01-03 17:11:47 708
原创 构造方法中调用父类中的构造方法
public class SuperTest extends Try{ public static void main(String args[]) { SuperTest tr=new SuperTest(); } public SuperTest() { super("rach"); }}cl
2014-01-03 16:42:04 867
原创 在构造方法中调用当前类的构造方法
public class ThisTest{ String name; int age; public ThisTest() { this("rach"); System.out.println("My name is :"+this.name+" and I am "+this.age+" years old"); } public ThisTest(String n
2014-01-03 16:06:45 1379
原创 构造方法重载和调用
public class Java9_10{ public static void main(String args[]) { Dong don=new Dong(); Dong dong=new Dong("lucy",23); }}class Dong{ String name; int age; public Dong() { this.name="john
2014-01-03 11:31:56 557
原创 注意静态代码块的使用
public class java9_7{ static String a="string-a"; static String b; String c="string-c"; String d; static { printStatic("before static"); b="string-b"; printStatic("after
2014-01-03 10:14:45 532
原创 对象数组的使用
//通过调用的方式复制,也可以通过构造方法赋初值,见下例!public class java9_6{ public static void main(String args[]) { Person []p=new Person[2]; p[0]=new Person(); p[1]=new Person(); p[0].know("sword", 1
2014-01-03 09:21:54 354
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人