Java Inheritance Analysis and java inheritance
After learning java, I started it again and suddenly found that I still don't understand inheritance. So I did a test to analyze it.
<Span style = "font-size: 18px;"> class A {public A () {sys ();} int a = 1; String ss = "hello "; public void fun () {test ();} public void test () {System. out. println ("this is a test method" + a);} public void sys () {System. out. println ("the output result is" + a) ;}} class B extends A {int a = 2; public B () {// sys ();} public void fun () {test ();}/* public void test () {System. out. println ("this is the result of Class B");} */public void sys () {System. out. println ("bbbbbbbbbbbbbbb") ;}} public class ExtendsTest {public static void main (String [] args) {B B B = new B (); B. test () ;}</span>
Although there are not many codes, it is not easy for me to fully understand them, so let's take a look,
Analysis
Class A {public A () {// constructor sys (); // method} int a = 1; String ss = "hello"; public void fun () {test ();} public void test () {System. out. println ("this is a test method" + a);} public void sys () {System. out. println ("the output result is" + a) ;}} class B extends A {int a = 2; public B () {// sys ();} // public void fun () {// test (); //} public void test () {System. out. println ("this is the result of Class B" + a);} public void sys () {System. out. println ("bbbbbbbbbbbbbbb") ;}} public class ExtendsTest {public static void main (String [] args) {B B B = new B (); B. fun (); // System. out. println (A); System. out. println (B );}}
This is an analysis chart I wrote. Due to the limited level, I hope you can point it out if you have any problems. Thank you.
This is the result after running
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.