About Java Inheritance Properties

Source: Internet
Author: User

This is just one thing to remember, any property of the parent class (the variable can be considered a property), the subclass can inherit and overwrite,Alltype (father)-"Changeanytype (son)--" AnyType

This is all the delegate properties of the parent class (which I can think of), including ordinary instance variables, modifiers, access permissions, data types, constant modifiers, static modifiers

Package extendvariable;

 Packageextendvariable; Public classAncestor {//Parent Class            intix=0;//Normal instance member properties    DoubleDX = 1;//instance member variables of different types    intbx=10000; Final intfy=2;//General Volume member properties        Static intsz=3;//normal static member properties        Private     intPrivar = 4;//member properties for different permissions                intDefVar = 5;//Default Permissions    protected     intProvar = 6;  Public        intPubvar = 7; }

Subclasses inherit the parent class through extend by changing the related property

 Packageextendvariable; Public classSonextendsancestor{//Change int to double, change double to int, type int to Boolean    DoubleIX = 0.1; intDX = 10; Booleanbx=true; //change ordinary constant variable to normal variable    intFY = 20; //to change a static member variable to a normal instance member variable    intSz=30; //turn all permissions upside down.     Public         intPrivar=40; protected      intDefvar=50; intProvar=60; Private     intPubvar=70;  Public  voidShowallmember () {System.out.println ("Ix=" + This. ix); System.out.println ("Dx=" + This. DX); System.out.println ("Bx=" + This. BX); System.out.println ("Fy=" + This. FY); System.out.println ("Sz=" + This. SZ); System.out.println ("Privar=" + This. Privar); System.out.println ("Defvar=" + This. DefVar); System.out.println ("Provar=" + This. Provar); System.out.println ("Provar=" + This. Pubvar); }         Public Static voidMain (String args[]) {son OA=Newson ();    Oa.showallmember (); }    }

The results are as follows:

ix= 0.1
dx= 10
bx= true
fy= 20
sz= 30
Privar= 40
Defvar= 50

This shows that any property of the parent class can be inherited and overwritten by the quilt class

About Java Inheritance Properties

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.