您的位置:首页 > 编程语言 > Java开发

some understanding about Java

2006-09-29 02:29 375 查看
  I began to read Java second time,during this time,I found that I've some different thinking with the first time.I neither know whichi is right,so I hope somebody can reply it can help me make sure it. Thanks a lot.

1.In the superclass, there is a abstract method,and the subclass isn't declare the mothed which is samed with superclass abstract the JVM will not compile.You need declare the subclass use abstract keyword,or you need to implement the abstract method in subclass.In other words,the subclass become the abstract class.

2.When use the abstract? When you are doing OOP,the method which is all exist between instance and instance and put them into the superclass.But there is no idea about what to the method should do,you can duplicated use the code by abstract and extends .For instance, there is a Animal class,and it have a sleep method,but it has different behaviors,maybe lie,hang or something like that,this time you can use abstract and extends to implement the relative sleep method by subclass.And when a class be signed the abstract keyword it can't instance.

3. Interface is important,it is good for communicate between blocks.When you set a interface,you create a class to implement it,you must run all abstract method and the method all use public keyword.You also can use it between two blocks,one class invoke the interface and the other implement the interface.But on this time the interface can not instance an object, so you must use its calling class instance an object,and let the reference instance assign to the interface's parameter.And it also can be extended,even it has more than one interface.And class can have many interfaces,when a class extends another class,the subclass can extends interfaces,just like subclass inherit method and variable from superclass.

Above these is only my thinking,maybe something right or not. And there are something i didn't refer,i'll do that later.I'm looking for your suggestion.And now,I also thank the people who give me hands,thank you so much,and have a good holiday,have a nice Middle-autumn day!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息