Home > Java > javaTutorial > How to access members in polymorphism in java

How to access members in polymorphism in java

王林
Release: 2023-04-29 15:10:06
forward
1100 people have browsed it

Explanation

1. Member variables, look at the left side when compiling, and look at the left side when running.

2.Construction methods, subclass constructions will access the parent class construction by default

3. Member methods, look on the left when compiling, and look on the right when running.

4. Static methods, look on the left when compiling, and look on the left when running.

Example

package day09;
/*
* 成员变量:
* 编译看左边(父类),运行看左边(父类)
* */
class Demo_PolyMorphic {
    public static void main(String[]args){
        Father f=new Son();
        System.out.println(f.num);
        Son s=new Son();
        System.out.println(s.num);
    }
}
 
class Father{
    int num=10;
}
class Son extends Father{
    int num=20;
}
Copy after login

The above is the detailed content of How to access members in polymorphism in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template