Java OOD Encapsulation Event

Source: Internet
Author: User

Wrap the child's waking situation into an event class

Test.java

Class Wakenupevent{private Long time;private string location;private child source;public wakenupevent (long time, string l Ocation, child source) {super (); this.time = Time;this.location = Location;this.source = Source;} Public long GetTime () {return time;} public void SetTime (long time) {this.time = time;} Public String getLocation () {return location;} public void setlocation (String location) {this.location = location;} Public child GetSource () {return source;} public void SetSource (child source) {This.source = source;}} Class Child implements Runnable {private dad dad;public Child (Dad dad) {This.dad = Dad;} public void WakeUp () {Dad.actiontowakenup (New Wakenupevent (System.currenttimemillis (), "bed", this)); @Overridepublic void Run () {try {thread.sleep;} catch (Exception e) {e.printstacktrace ();} WakeUp ();}} Class Dad {public void Actiontowakenup (Wakenupevent e) {System.out.println (E.gettime ()); System.out.println (E.getlocation ()); System.out.println (E.getsource ()); System.out.println ("Fedd the Child ");}} public class Test {public static void main (string[] args) {Dad d = new Dad (); Child C = new Child (d); new Thread (c). Start ();}}

  

Operation Result:

Java OOD Encapsulation Event

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.