Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java inheritance initialization problem     - Linux common network tools: batch scanning of hosting services netcat (Linux)

- Linux kernel RCU (Read Copy Update) lock Brief (Linux)

- New experience Budgie (Budgerigar) desktop environment (Linux)

- Python class of operator overloading (Programming)

- Shell scripts get a snapshot of the page and generates thumbnails (Linux)

- CentOS 6.4 install and configure Squid Proxy Server (Linux)

- Java Annotation Comments (Programming)

- High-performance JavaScript DOM programming (Programming)

- Lenovo E431 notebook CentOS system is installed wireless network card driver (Linux)

- Linux Command-line MySQL summary (Database)

- When the master key encounter NULL (Database)

- Python several standard types of built-in functions (Programming)

- Linux create and delete user step (Linux)

- PL / SQL in forall simple test (Database)

- Python Socket Network Programming (Programming)

- Ubuntu 14.04 LTS 64-bit install GNS3 1.3.7 (Linux)

- Linux operating system ARP Spoofing Defense (Linux)

- Let Linux boot methods to enter characters interface and set FrameBuffer resolution methods (Linux)

- Android Get App version number and version name (Programming)

- MySQL 5.7 perfectly distributed transaction support (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:      
 
- Safety testing Unix and Linux server entry succinctly (Linux)
- How to use the ftp tool to transfer files between Windows and Linux (Linux)
- Linux commands with browsing and downloading files (Linux)
- Large computer network security policy Experience (Linux)
- C ++ copy constructor (Programming)
- MySQL primary and secondary replicate data inconsistencies (Database)
- Nagios plugin installation tutorial of Nrpe (Linux)
- RabbitMQ Getting Started Tutorial (Linux)
- A step by step teach have to install multi-node cluster configuration Hadoop (Server)
- PL / SQL how to make the program every few seconds to insert a data (Database)
- Bash common several configuration files (Linux)
- Cobbler Add custom YUM source (Linux)
- CentOS 7 server environment to quickly build Linux (Server)
- Getting Started with Linux system to learn: how to check the version of SSH on Linux (Linux)
- Upgrading to Debian 7.6 glibc 2.15 (Linux)
- Construction Spark source and application development environment (Server)
- sudo command scenario analysis (Linux)
- Using DOS command to change UNIX administrator password (Linux)
- On Android running ClojureScript (Linux)
- Cygwin install Python MySQLdb (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.