In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the relevant knowledge of "what is the use of the Java this keyword?". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what is the use of the Java this keyword?" can help you solve the problem.
Boy class package myjava1;public class Boy {private String name; private int age; public Boy () {} public Boy (String name,int age) {this.name = name; this.age = age;} public String getName () {return name } public void setName (String name) {this.name = name;} public int getAge () {return age;} public void setAge (int age) {this.age = age } public void marry (Girl girl) {System.out.println (this.name+ "also wants to marry:" + girl.getName ());} public void shout () {if (this.age > = 22) {System.out.println ("OK") } else {System.out.println ("cannot");} Girl class package myjava1;public class Girl {private String name; private int age; public Girl () {} public Girl (String name,int age) {this.name = name This.age = age;} public String getName () {return name;} public void setName (String name) {this.name = name;} public int getAge () {return age;} public void setAge (int age) {this.age = age } public void marry (Boy boy) {System.out.println (this.name + "want to marry:" + boy.getName ()); boy.marry (this) } public void compare (Girl girl) {if (this.age > girl.getAge ()) {System.out.println (this.getName () + "than" + girl.getName () + "large") } else if (this.age < girl.getAge ()) {System.out.println (this.getName () + "than" + girl.getName () + "smaller");} else {System.out.println (this.getName () + "as big as" + girl.getName () + ")) } BoyGirlTest class package myjava1;public class BoyGirlTest {public static void main (String [] args) {Boy boy = new Boy ("Romeo", 21); boy.shout (); Girl girl = new Girl ("Juliet", 18); girl.marry (boy) Girl girl2 = new Girl (Zhu Yingtai, 19); girl2.compare (girl); girl.compare (girl2); girl2.compare (girl2);}}
Running result
This is the end of the content about "what are the ways to use Java this keywords". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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: 0
*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.