Java Inheritance Analysis and java inheritance

Source: Internet
Author: User

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.

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.