`

subclass extends the superclass

 
阅读更多

Natrual world has its amazing method to multiply and evolve .It is inheritance. And in the virual world, we use the extends to replace inherited methods. Just like the chick has only one father and one mother ,one subclass also has only one superclass. Subclass can inherit the methods and instance variables totally from its superclass. Because subclass has its own thoughts so it can add new methods and instances variable ,furthermore,

It can override the methods it inherited from the superclass. If you want to see it more clear, just to design the inheritance tree for an animal simulation program.<>.

 

Because the limited words, the subclass can only use some instance variables



 

1.when all class are in the same package

 

 2.When the superclass int another  package

it can only use public *****;

MORE    An adequate account:

Private ONLY use in the clss

Default  in the package

Protected in the package and the subclass in another package

Public in the all package

 

Automatic data trasformation in java

(1)subclass can turn into superclass

(2)type can trun into int

You can find it shadow in

/*JFrame add method and setLayout method*/

 
How to define a interface
eg.public interface NAME{}
Warning
1.It only can use public
2.constant name must be  the capital letter  and it can only define constant
3interface can inplements interface
eg.Public interface NAME implements  interface interface ,,,,(){}.

How to define an abstract class

Answer: A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.
 Example of Abstract class:
abstract class testAbstractClass {
 protected String myString;
 public String getMyString() {
 return myString;
}
public abstract string anyAbstractFunction();
interface and abstract class can't define an object.
  • 大小: 4.1 KB
  • 大小: 4.4 KB
  • 大小: 61.1 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics