java vamei_Java快速教程--vamei 学习笔记(基础篇)

链接:http://www.cnblogs.com/vamei/archive/2013/03/31/2991531.html

java快速教程第1课 从HelloWorld到面向对象

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/14/2958654.html

java快速教程第2课 方法与数据成员

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/25/2964430.html

java快速教程第3课 构造器与方法重载

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/26/2981728.html

java快速教程第4课 封装与接口

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/27/2982209.html

public classTest

{public static voidmain(String[] args)

{

Human aPerson= new Human(160);

System.out.println(aPerson.getHeight());

aPerson.growHeight(170);

System.out.println(aPerson.getHeight());

aPerson.repeatBreath(100);

}

}classHuman

{/*** constructor*/

public Human(inth)

{this.height =h;

System.out.println("I'm born");

}/*** accessor*/

public intgetHeight()

{return this.height;

}/*** mutator*/

public void growHeight(inth)

{this.height = this.height +h;

}/*** encapsulated, for internal use*/

private voidbreath()

{

System.out.println("hu...hu...");

}/*** call breath()*/

public void repeatBreath(intrep)

{inti;for(i = 0; i < rep; i++) {this.breath();

}

}private int height; //encapsulated, for internal use

}

java快速教程第5课 实施接口

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/29/2982206.html

packagetext;interfaceCup

{void addWater(intw);void drinkWater(intw);

}class Text implementsCup

{public void addWater(intw)

{this.water = this.water +w;

System.out.println(water);

}public void drinkWater(intw)

{this.water = this.water -w;

System.out.println(water);

}public intwaterContent( )

{return this.water;

}public voidplay( )

{

System.out.println("la...la...");

}private int water = 0;public static voidmain(String args[ ])

{

Text obj= newText( );

obj.addWater(10);

obj.drinkWater(4);

}

}

java快速教程第6课组合

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/29/2982206.html

packagetext;public classText

{public static voidmain(String[] args)

{

Torch aTorch= newTorch( );

System.out.println("Charge: 2 hours");

aTorch.charge(2);

System.out.println("First Turn On: 3 hours");

aTorch.turnOn(3);

System.out.println("Second Turn On: 3 hours");

aTorch.turnOn(3);

}

}classBattery

{public void chargeBattery(doublep)

{if (this.power < 1.)

{this.power = this.power +p;

}

}public boolean useBattery(doublep)

{if (this.power >=p)

{this.power = this.power -p;return true;

}else{this.power = 0.0;return false;

}

}private double power = 0.0;

}classTorch

{/*** 10% power per hour use

* warning when out of power*/

public void turnOn(inthours)

{booleanusable;

usable= this.theBattery.useBattery(hours*0.1);if ( usable != true)

{

System.out.println("No more usable, must charge");

}

}/*** 20% power per hour charge*/

public void charge(inthours)

{this.theBattery.chargeBattery(hours*0.2);

}/*** composition*/

private Battery theBattery = newBattery();

}

java快速教程第7课 包的建立和使用

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/29/2982206.html

e2568af4384d6c74dc784c1d9fec9e19.png

d22aced88ebdc3a46a5ce955ece3464f.png

a02ea5240b972718c58ca77f6abca43f.png

java快速教程第8课 继承

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/29/2982232.html

packagetest;public classTest

{public static voidmain(String[ ] args)

{

System.out.println("hello world");

Woman aWoman= newWoman();

aWoman.growHeight(120);

System.out.println(aWoman.getHeight());

aWoman.breath();

aWoman.giveBirth();

}

}classHuman

{/*** contructor*/

public Human(intheight)

{this.height =height;

}publicHuman()

{

}/*** accessor*/

public intgetHeight()

{return this.height;

}/*** * mutator*/

public void growHeight(inth)

{this.height = this.height +h;

}/*** breath*/

public voidbreath()

{

System.out.println("hu...hu...");

}private intheight;

}class Woman extendsHuman

{/*** constructor*/

public Woman(inth)

{super(h); //base class construtor

System.out.println("Hello, Pandora!");

}publicWoman()

{

}/*** new method*/

publicHuman giveBirth()

{

System.out.println("Give birth");return (new Human(20));

}/*** override Human.breath( )*/

public voidbreath()

{super.breath( );

System.out.println("su...");

}

}

java快速教程第9课  类数据与类方法

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/31/2988622.html

packagetest;public classTest

{public static voidmain(String[ ] args)

{

System.out.println(Human.getPopulation());

Human aPerson= new Human(160);

System.out.println(aPerson.getPopulation());

}

}classHuman

{/*** constructor*/

public Human(inth)

{this.height =h;

Human.population= Human.population +1;

}/*** accessor*/

public intgetHeight()

{return this.height;

}/*** mutator*/

public void growHeight(inth)

{this.height = this.height +h;

}/*** breath*/

public voidbreath()

{

System.out.println("hu...hu...");

}private intheight;/** static method, access population*/

public static intgetPopulation()

{returnHuman.population;

}private static intpopulation;private static boolean is_mammal = true;

}

java快速教程第10课 接口的继承与抽象类

学习网址:http://www.cnblogs.com/vamei/archive/2013/03/31/2982240.html

java快速教程第11课 对象引用

学习网址:http://www.cnblogs.com/vamei/archive/2013/04/01/2992484.html

packagetest;public classTest

{public static voidmain(String[] args)

{

Human aPerson= new Human(160);

Human dummyPerson=aPerson;

System.out.println(dummyPerson.getHeight());

aPerson.growHeight(20);

System.out.println(dummyPerson.getHeight());

}

}classHuman

{/*** constructor*/

public Human(inth)

{this.height =h;

}/*** accessor*/

public intgetHeight()

{return this.height;

}/*** mutator*/

public void growHeight(inth)

{this.height = this.height +h;

}private intheight;

}

java快速教程第12课 多态

学习网址:http://www.cnblogs.com/vamei/archive/2013/04/01/2992662.html

将一个衍生类引用转换为其基类引用,这叫做向上转换(upcast)或者宽松转换。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值