In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use the super keyword about Java object-oriented. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
/ * * this: represents the reference 1 of the current class. When the local variable and the member variable have the same name, the member variable should be qualified by this 2. When instantiating, you can use this to call the constructor of the current class, which must be written in the first line 3. 0. You can use this to call the current class's normal method super: a reference to the current parent class. When instantiating a subclass, you can use super to call the parent class's non-private method 2. 0. When instantiating a subclass. You can call the constructor of the parent class with super, which must be written in the first line 3. 0. In the methods of the subclass, you can use supe to call the non-private methods of the parent class. * / public class Test1 {public static void main (String [] args) {/ / instantiate farmer Father father = new Father (); father.setName ("farmer"); father.setAge (90) System.out.println (father.getAge () + "year" + father.getName () + "you" + father.getWealth ()); Father father = new Father ("Farmer", 90); System.out.println (father.getAge () + "year" + father.getName () + "you" + father.getWealth ()) Son son = new Son ("Farmer", 90); System.out.println ("son knows his father:" + son.getAge () + "year" + son.getName () + "you" + son.getWealth ()); son.work ();}} / / parent class Father {private String name; private int age; private String wealth Public Father () {wealth = "100 taels of gold";} public Father (String name, int age) {this (); this.name = name; / / this.age=age; this.setAge (90);} public void work () {System.out.println ("cultivated land") } public String getWealth () {return wealth;} public void setAge (int age) {this.age = age;} public int getAge () {return age;} public void setName (String name) {this.name = name } public String getName () {return name;}} / / subclass class Son extends Father {public Son (String name, int age) {super (name, age); / / super.setName (name); / / super.setAge (age);} public void work () {super.work () System.out.println ("the son seeks the golden treasure"); System.out.println ("only through your own hard work can you get the fruit is the greatest treasure") }} this is the end of the article on "how to use the super keyword of Java object-oriented". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 299
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.