Example 1 in java

Source: Internet
Author: User

If the member variables defined in the subclass have the same name as those defined in the parent class, the subclass hides the member variables inherited from the parent class. When a method is defined in the subclass, and the method name, return type, number of parameters are identical to a method of the parent class, the method inherited from the parent class of the subclass will be hidden. If you want to use the hidden member variables or methods of the quilt class in the subclass, you can use the keyword super [html] class student {int number; String name; student () // use the constructor {} student (int number, String name) {this. number = number; // use the this keyword to call the member variable this. name = name; System. out. println ("I am" + name + "my number is" + number) ;}} xiongyao @ xiongyao-Lenovo :~ /Java programming $ javac example7.java class univer_student extends student {boolean marital status; univer_student (int number, String name, boolean B) {super (number, name); marital status = B; System. out. println ("Marital status =" + marital status) ;}} public class example7 {public static void main (String args []) {univer_student zhang = new univer_student (9901, "Xiong Yao ", false) ;}} xiongyao @ xiongyao-Lenovo :~ /Java programming $ javac example7.javaxiongyao @ xiongyao-Lenovo :~ /Java programming $ java example7I am Xiong Yao my number is 9901 marital status = false

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.