Public class Parent class {
Public String name="name of the parent class";
Public String parent name="name of the parent class";
Public class Child class extends ParentClass {
Private String the child the name;
}
Public static void main (String [] args) {
ChildClass child=new ChildClass ();
System. The out. Printing (child. ParentName);
}
}
After you've written in the ChildClass child=new ChildClass (); An error, why? Can we write the wrong inheritance itself, can't write this
CodePudding user response:
Baidu a Java classes inherit code, or you directly according to the copy of the book, you own write no place is right, solid knowledge have to learn the basis of a bit, right
CodePudding user response:
The
refer to the original poster hurricane 飗 response: public class Parent class { Public String name="name of the parent class"; Public String parent name="name of the parent class"; Public class Child class extends ParentClass { Private String the child the name; } Public static void main (String [] args) { ChildClass child=new ChildClass (); System. The out. Printing (child. ParentName); } } After you've written in the ChildClass child=new ChildClass (); An error, why? Whether inheritance is write wrong, can't write the Case you noticed? Post the right code, the Child from the class looks, CodePudding user response:
You this few lines of code is really horrible, do you want to subclass call the parent class attribute? Public class Parent { Public String name="name of the parent class"; Public String parent_name="superclass name"; Public static void main (String [] args) { The Child Child=new Child (); System. The out. Print (child. Parent_name); } } The class Child extends the Parent { Private String name; } CodePudding user response:
If take no account of problem of writing code, you are a subclass of the parent class inner class, so when the parent class instance is not created, cannot create inner class alone, CodePudding user response:
1/f, reference source is a ghost reply: baidu a Java classes inherit code, or you directly according to the copy of the book, you own write no place is right, solid knowledge have to learn the basis of a bit, right a bit Thank you for your help CodePudding user response:
reference Type11 reply: 3/f you this few lines of code is really horrible, do you want to subclass call the parent class attribute? Public class Parent { Public String name="name of the parent class"; Public String parent_name="superclass name"; Public static void main (String [] args) { The Child Child=new Child (); System. The out. Print (child. Parent_name); } } The class Child extends the Parent { Private String name; } Thank you for your help CodePudding user response:
reference 4 floor qq_39936465 response: if take no account of problem of writing code, you are a subclass of the parent class inner class, so when the parent class instance is not created, cannot create inner class alone, Thank you for your help