Java学习小结
2018-05-24 本文已影响26人
子沵
本文主要对java中面向对象相关进行总结.
如果你从以下代码中提取出了任何角色、情节或思想,那一定是因为你的想象力太过丰富,而绝非因为我把写小说时的臭毛病给带到了写代码中.
面向对象编程Object Oriented Programming
import com.man.thought;
public abstract class OOP{
anytype property;//假装有anytype;
someact method;//假装有someact;
public abstract void everythingIsObject();
public abstract void newAnObject();
}
public class Encapsulation extends OOP{
private anytype property;//私有属性神圣不可侵犯!
private someact method;//并非所有的对象都像我这样优秀
public Encapsulation(anytype property,someact method){
this.property=property;!!##@$@$@*(&==>
his.property=property;//Is THIS? NoT! HIS!
his.method=method;
/*
DECLARING IS ACHIEVING.宣称即实现.
SEEING IS OWNING. 所见即所得.
MY-THOUGHT IS METHOD. 思想即行为.
*/
}
@override
public void everythingIsObject(keyword "private"){
System.out.println("朕皇考兮Object,执权柄兮private;
If a man modified,he'll never get back.'");
}
@override
public void newAnObject(keyword "set"&"get"){
//saith my God:"Sometimes "private" is good,
but always "public" people need."
//if you want, force to "set" it public,
and then all you guys "get" it.
Encapsulation his=new Encapsulation(property,method);
his.getProperty();
}
public void setProperty(anytype property){
System.out.println("当朝内务官,统共有五位.如今五位已去了三位.
朕给你们钥匙让你们管理朕的private property,对你们是推心置腹.可你们呢?")
}
public anytype getProperty(){
System.out.println("朕get你的才是你的,朕若不get,你什么也别想得到.");
return this.Property;
System.outpintln("我大Java"+year+"年的基业,竟也要亡了吗?")
}
}
public class Extends extends OOP{
public Extends(){
this("少量财产","一些方法");
}
public Extends(hyperString property,hyperAct method){
this.property=property;
this.method=method;
}
@override
public void everythingIsObject(keyword "extends"){
System.out.println("我的子类的子类,依然是我的子类.");
System.out.println("我的父类的父类,间接是我的父类.");
System.out.println(
"Object是所有类之父.
父说,子extends父,子之子extends子,父子相继,犹如根系.
向上为父系,向下为子系.
为父者,子系蔓延,可多重派生;为子者,父系唯一,溯源归根必要指向Object"
)
@override
public void newAnObject(keyword "interface"&"implements"){
System.out.println("我的对象说,父不让我们搞对象,这是不利的.")
//父作了规定,要使它根系分明,可蔓延却不可相交.
System.out.println("我的对象又说,接口是好的,接口是善的,接口的使用是有利的.")
//通过接口,不同的类或对象可以相互插入,相互implements,这实际上就是子系相交,
多向扩展,但却并不违反父的规定.
System.out.println("我明白,interface接口,就是让有需求的对象们打破禁忌、
见面交流的借口.")
}
import com.aphrodite.love;
public class Polymorphism extends OOP{
String thought;
public Polymorphism(){
this("衣父衣","执子手");
}
public Polymorphism(hyperString property,hyperAct method){
this.property=property;
this.method=method;
}
public String thinking(String thought){
this.thought=thought;
return this.thought;
}
private String loving(Object someone){
this.thought=someone.beauty(this, true);
return this.thought;
}
@override
public void newAnObject(keypoint "transformation"){
OOP anObj=new Polymorphism();//upwards transformation 向上转型
anObj.thinking("向上转型是好的,穿上父的衣服,以父的名义行事,
便俨然感觉自己也是一位大人了.");
System.out.println(this.thought);
anObj.loving~$%@$%^==>anObj.thinking(
"I am sure, I love her.
但是我穿着父的衣服,正在以父的名义行事,我无法向她示爱.
因为父并不具备关于爱的method."
)
Polymorphism qBit=(Polymorphism)anObj;
qBit.thinking("
我脱下了父的衣服,我完成了downwards transformation.
我终于又是自己了,我可以尝试去loving了."
)
qBit.loving(aGirlCalledXiaofang);
System.out.println(this.thought)
//"小芳,求求你不要走.小芳,求求你再给我一个爱的接口."
}