[Original] subclass Access Base Class Method

Source: Internet
Author: User
Problem
Class A is the base class
Class B inheritance and Class
Class C inheritance and Class B
At the same time, method F is available in all three classes.
How can I access Class A through class C objects ???

This problem is easily misleading: Super. Super. F ();

The correct method is to use a subclass object to access the base class method.
Declare the method as static.Subclass Object Access Base Class Method
Code Implementation: 1 Class A {
2   Static   Void F () {
3System. Out. println ("Hello,");
4}
5
6 }
7
8 Class B Extends A {
9
10   Static   Void F () {
11System. Out. println ("Hello, B");
12}
13
14 }
15
16 Class Testa {
17   Public   Static   Void Main (string [] ARGs) {
18 B =   New B ();
19 B. F (); // Jdk1.4 outputs "Hello, B"
20 A =   New B ();
21 A. F (); // The result output in jdk1.4 is "Hello,"
22 }
23 }
24
25

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.