20 Replication of functions

Source: Internet
Author: User

Learning Essentials


    1. Replication of functions (override)

    2. Call the member function of the parent class using Super


This (): Call a constructor in this class

This. : Call a member function in this class


Super (): Call the constructor in the parent class

Super (): Call a member function in the parent class

Class person{string name, int age, void introduce () {System.out.println ("My Name is" +name+ ", I Am" + ");}
Replication (override)//1. In the two classes that have a parent-child relationship,//2. The parent class and subclass each have a function, the definitions of the two functions (return value type, function name, and argument list) are exactly the same class Student extends person{string  Address;void introduce () {//system.out.println ("My name is" + name+ ", my Age is" +age "); Super.introduce ();//Call the parent class member function Objective to reduce duplication of code System.out.println ("My home in" + Address);}}
Class Test{public static void Main (String args[]) {Student s = new Student (); s.name = "Lin Feng"; s.age = 20;s.address = "Beijing"; s.in Troduce ();}}

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/1C/wKiom1R4LBCw4q4XAAAwq0lnIl8427.jpg "title=" 1.jpg " alt= "Wkiom1r4lbcw4q4xaaawq0lnil8427.jpg"/>

20 Replication of functions

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.