`

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
分享到:
评论

相关推荐

    类继承构造方法super()调用可以吃吗

    class SubClass extends SuperClass { int x; SubClass() { super(); // 调用父类的构造方法 x = 5; // super()必须是子类构造器的第一条语句 System.out.println("in SubClass :x=" + x); } void ...

    Test_invoke_super_range.rar_Superclass

    class Subclass extends Superclass { public Subclass() { super(); } // 调用Superclass的无参构造器 public Subclass(int x) { super(x); } // 调用Superclass的带参数构造器 } ``` 2. **方法调用**:如果...

    Test_invoke_super.rar_Superclass

    class Subclass extends Superclass { void method() { super.method(); // 调用超类的方法 System.out.println("Subclass method"); } } ``` 在C语言中,由于没有内置的面向对象特性,我们可以使用以下方式...

    java学习笔记

    部分内容如下所示: 继承使的复用以前的代码非常容易,...继承语法:修饰符 class Subclass extends superClass{ // 类定义部分 } java中的继承:只支持单继承(每个类只能有一个直接父类),is a的关系(特殊与一般的

    继承多态重载与接口PPT学习教案.pptx

    class SubClass extends SuperClass { // ... } ``` 这里,`SubClass`是子类,而`SuperClass`是父类。子类可以访问父类中所有的非私有(`public`和`protected`)成员,包括字段和方法。如果没有显式指定父类,那么...

    java教程之java继承示例详解

    继承的格式是"class SubClass extends SuperClass { //执行语句;}",其中SuperClass是父类,SubClass是子类。super关键字和this关键字的用法相同,super代表父类引用,this代表本类引用。当子类和父类出现同名成员...

    论JAVA继承机制中父类与子类的关系

    public class SubClass extends SuperClass { // 子类的具体实现 } ``` 创建子类对象的一般格式如下: ```java SubClass subObj = new SubClass(); ``` ##### 2. 创建过程 - 当创建子类对象时,子类的构造器会...

    JAVA技术专题综述之构造方法篇

    public class SubClass extends SuperClass { SubClass() { System.out.println("SubClass constructor"); } public static void main(String[] args) { SubClass sub = new SubClass(); } } ``` **输出结果...

    实验三Java类的继承与派生

    public class SubClass extends SuperClass { // 子类的具体实现 } ``` #### 构造方法与继承 构造方法不会被继承,但是子类可以通过调用父类的构造方法来初始化父类中的成员变量。通常情况下,子类的构造方法会...

    常见常用api

    public class SubClass extends SuperClass implements SuperInterface { { System.out.println("init SubClass field"); } public SubClass() { System.out.println("init SubClass Constructor"); } public ...

    Java程序设计实用教程-电子教案-5继承与接口(ppt文档).ppt

    public class SubClass extends SuperClass { // ... } ``` 在上面的例子中,SubClass是SuperClass的子类,继承了SuperClass的所有成员变量和方法。 在Java语言中,继承有两个主要特点:单继承和多态性。单继承...

    subclass-dance-party

    2. **ES6的class语法**:使用`class SubClass extends SuperClass {}`创建子类,继承自SuperClass。这种方式更简洁,但本质上仍然是原型继承。 3. **使用Object.create()**:对于简单的继承,可以使用`SubClass....

    java中构造方法和方法全面解析.pdf

    public class SubClass extends SuperClass { SubClass() { System.out.println("SubClass constructor"); } public static void main(String[] args) { new SubClass(); } } ``` 当运行`new SubClass()`时...

    继承与方法的重载学习代码

    public class SubClass extends SuperClass { // 子类的代码 } ``` 这里的`SubClass`是子类,`SuperClass`是父类。子类可以访问父类的非私有(public或protected)字段和方法,同时也可以添加自己的特性和功能。 ...

    Java_programming_code_inheritance_Thread.rar_inheritance

    class SubClass extends SuperClass { // 子类的方法和成员变量 } ``` 这里,`SubClass`是子类,`SuperClass`是父类。子类可以直接访问父类的非私有(public和protected)成员,并可以重写父类的方法以提供不同的实现...

    java程序.txt

    class SubClass extends SuperClass { private int n; SubClass(int n) { super(); // 调用父类无参构造器 System.out.println("SubClass(" + n + ")"); this.n = n; } SubClass() { super(300); // 调用...

    第05章 面向对象高级程序设计.ppt

    - 在Java中,子类声明通常包含`extends`关键字,如`class SubClass extends SuperClass`,表明SubClass是SuperClass的子类。 - 子类可以访问父类中`public`、`protected`和默认(包访问)权限的成员,但不能访问`...

    java 继承和多态的讲解

    public class SubClass extends SuperClass { public SubClass() { super(); // 调用 SuperClass 的默认构造器 } } ``` `final`关键字在Java中用于声明不可变的对象、变量或方法。当一个类被声明为`final`,它不...

    03_OOP_3_继承

    class SubClass extends SuperClass { // 子类的属性和方法 } ``` 这里,`SubClass`是子类,它继承了`SuperClass`的属性和方法。子类可以覆盖(Override)父类的方法,以提供自定义的行为。例如: ```java public...

    Java Methods-Class Hierarchies and Interfaces.ppt

    例如,`Superclass`(基类)和`Subclass`(派生类)之间的关系,子类可以通过关键字`extends`来继承父类: ```java public class Subclass extends Superclass { // ... } ``` 类层次结构是通过继承构建的一系列...

Global site tag (gtag.js) - Google Analytics