Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java inheritance initialization problem     - Simple to use Linux GPG (Linux)

- The bulk batch multiple rows of data collect (Database)

- Realization of Linux operating system illegal IP censorship (Linux)

- LaTeX Getting Started Tutorial (Linux)

- iTerm - let your command line can also be colorful (Linux)

- Linux mount command Detailed (Linux)

- sudoers file parsing (Linux)

- Orabbix binding Python send graphical reports (Linux)

- Oracle creates split and splitstr functions (Database)

- CentOS6.3 build a Python 3.3 environment to access Oracle 11gR2 (Database)

- Tsung first test installation (Linux)

- Use small network command to check whether PC Security (Linux)

- How to add a new hard disk without restarting the CentOS 7 / RHEL 7 virtual machine (Linux)

- Linux System Getting Started Learning: Repair fatal error openssl aes h no such file or directory (Linux)

- Installation of JDK and Tomcat under Linux (CentOS) (Linux)

- Linux System Getting Started Learning: Linux how to install 7zip (Linux)

- Linux_Logo - output color ANSI Linux distributions logo command-line tool (Linux)

- MySQL simple operation notes under Linux (Database)

- CentOS7 virtual machine creation failed Solution (Linux)

- Hazelcast integration with MongoDB (Database)

 
         
  Java inheritance initialization problem
     
  Add Date : 2017-04-13      
         
       
         
  Look at the code said the results

public class Dervied extends Base {

    private String name = "dervied";
    public Dervied () {
        tellName ();
        printName ();
    }
    public void tellName () {
        System.out.println ( "Dervied tell name:" + name);
    }
    public void printName () {
        System.out.println ( "Dervied print name:" + name);
    }
    public static void main (String [] args) {
        new Dervied ();
    }
}
class Base {
    private String name = "base";
    public Base () {
        tellName ();
        printName ();
    }
    public void tellName () {
        System.out.println ( "Base tell name:" + name);
    }
    public void printName () {
        System.out.println ( "Base print name:" + name);
    }
}
The result:
Dervied tell name: null
Dervied print name: null
Dervied tell name: dervied
Dervied print name: dervied

Why is this so
Regardless of the name and modify Base is public or protected, the results are like this.
Even the code into this, or the result (name field Base class changed basename)

public class Dervied extends Base {

    private String name = "dervied";
    public Dervied () {
        tellName ();
        printName ();
    }
    public void tellName () {
        System.out.println ( "Dervied tell name:" + name);
    }
    public void printName () {
        System.out.println ( "Dervied print name:" + name);
    }
    public static void main (String [] args) {
        new Dervied ();
    }
}
class Base {
    public String basename = "base";
    public Base () {
        tellName ();
        printName ();
    }
    public void tellName () {
        System.out.println ( "Base tell name:" + basename);
    }
    public void printName () {
        System.out.println ( "Base print name:" + basename);
    }
}

God gave away a large background
Constructor Base, two methods tellName and printName calls, because inheritance reasons, it should do is subclass method, the subclass this case has been initiated, the data members, so the display is null.
     
         
       
         
  More:      
 
- Ubuntu 14.04 / Linux Mint 17 How to install the MintMenu 5.5.2 menu (Linux)
- Justniffer installed on Ubuntu 15.04 (Linux)
- How to disable UEFI to install Linux on Win8 (Linux)
- Linux System Getting Started Tutorial: How to find the maximum memory your system supports (Linux)
- Xshell upload files to achieve Windows host Linux (Linux)
- Virt Related Command Summary (Linux)
- Linux remote connectivity tools -OpenSSH (Linux)
- Function Getting the Linux shell (Programming)
- Spring inject a type of object to enumerate (Programming)
- Examples of testing and installation Mesos on CentOS (Linux)
- Monitoring Linux System 7 command-line tool (Linux)
- Oracle Client Easy Connection error ORA-12154, TNS-03505 (Database)
- Linux user status query, and to unlock locked user (Linux)
- Several reasons MySQL garbled (Database)
- How to deploy Icinga client (Server)
- Seven Steps to Help Google Chrome Speed - (Linux)
- Getting Started with Linux system to learn: How to compress JPEG images on the command line (Linux)
- Oracle procedure or function Empty Table (Database)
- MySQL / MariaDB database master-slave replication (Database)
- Install Oracle JDK 8 and JVM class loading mechanism in Linux (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.