JAVA subclass accesses parent class protected scope member variables

protected scope supports access to this package and subclasses

parent class Public Class A {

protected String name = "zs";

}

subclass:

Public Class B extends A {

public void test () {

System.out.print (name);

/ / Why does it not support access in this way of new A () .name? isn"t this also called access in a subclass? }

}

Aug.25,2021

if you are accessing this field in the same package, this access support is supported. If you cross the package, you won't be able to access it.


is actually accessible as long as you access the current instance 's own protection variable, rather than another instance of someone else's variable, regardless of whether that person is also surnamed Zhao or not.

you can take a look at this blog
http://www.blogjava.net/NewMo.
and this
https://stackoverflow.com/a/3.

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ebef72-2a13.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ebef72-2a13.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?