Package app; Public interface idisk { Public abstract string readinfo (); Public abstract void writeinfo (string MSG ); } Package USB disk; Import app. idisk; Public class usbdisk implements idisk { Public String readinfo (){ Return "Information read from the USB flash drive "; } Public void writeinfo (string MSG ){ System. Out. println ("write information to the USB flash drive:" + MSG ); } } Package movedisk; Import app. idisk; Public class movedisk implements idisk { Public String readinfo (){ Return "Information read from mobile hard disk "; } Public void writeinfo (string MSG ){ System. Out. println ("write information to the mobile hard disk:" + MSG ); } } Import java. AWT. frame; Import org. springframework. Context. applicationcontext; Import org. springframework. Context. Support. filesystemxmlapplicationcontext; Import app. idisk; Public class test { Public static void main (string [] ARGs ){ Applicationcontext context = New filesystemxmlapplicationcontext ("applicationcontext. xml "); Idisk disk = (idisk) Context. getbean ("disk "); // Instantiate the object based on the content of the configuration file and return Disk. readinfo (); } } |