In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the example analysis of anonymous internal classes in Java object-oriented. It is very detailed and has a certain reference value. Interested friends must read it!
/ * * knowledge: anonymous Internal topic: there is an alarm on the motorcycle. When someone touches the motorcycle, the alarm will sound. Abstract class: 1.1motorcycle (Moto), alarm (Alarm), human (Person) 2. Find out the class relationship: 2.1Motorcycle equipped with alarm Alarm-> Moto (1 to 1) 2.2.2.The alarm has different brand classification Alarm 3. Find out the class attributes: 3.1 Moto (brand, alarm reference) 3.2 Alarm (brand) 3.3 Person (name) 4. Moto {load (Alarm alarm)} 4.2.When the motorcycle Person {touch (Moto moto)} 4.3alarm sounds, Alarm {beep ()} * / public class TestMoto {public static void main (String [] args) {/ / prepare to produce a southern motorcycle Moto moto = new Moto ("South") / / A small power alarm moto.load (new SmallAlarm ()) was installed on the motorcycle; / / at this time Li Ming came over Person p = new Person ("Li Ming"); / / Li Ming accidentally ran into the motorcycle, and the motorcycle issued an alarm sound p.touch (moto). }} interface Alarm {/ / alarm can sound public void beep ();} class SmallAlarm implements Alarm {/ / alarm can sound public void beep () {System.out.println ("someone has touched me and may steal a motorcycle");}} class Moto {private String brand;// brand private Alarm alarm / / alarm reference public Moto (String brand) {this.brand = brand;} public Alarm getAlarm () {return this.alarm;} / / load alarm public void load (Alarm alarm) {this.alarm = alarm;}} class Person {private String name / / name public Person (String name) {this.name = name;} / / someone touches the motorcycle, and the alarm on the motorcycle sounds public void touch (Moto moto) {moto.getAlarm (). Beep () }} these are all the contents of the article "sample Analysis of Anonymous Internal classes in Java object-oriented". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.