Home >Java >JavaBase >Will java variables be inherited?

Will java variables be inherited?

angryTom
angryTomOriginal
2019-11-18 14:34:313586browse

Will java variables be inherited?

Will java variables be inherited?

Variables in java will be inherited, provided that they are member variables of the parent class Type is public or protected. When the member variables of the parent class are private, they cannot be inherited, but they can be accessed through the corresponding methods provided by the parent class.

1. Subclasses can directly use non-private members of the parent class

Will java variables be inherited?

Therefore, variables generally declared in the parent class , do not declare it again in subclasses;

2. Subclasses can use the private members of the parent class through the functions provided by the parent class

Will java variables be inherited?

3. The subclass defines members with the same name as the parent class. Direct access through the subclass is the members defined in the subclass

Will java variables be inherited?

4. The subclass defines members with the same name as those in the parent class. To access the members of the parent class, you can use the super keyword

Will java variables be inherited?

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

The above is the detailed content of Will java variables be inherited?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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