Package Singleton

Examples of Singleton.ContactList


   
    System.out.println("SINGLETON DEMO");
    System.out.println();
   
    //Create a contact list
    ContactList myContacts = ContactList.getInstance();
   
    //Add a contact
    Contact newContact1 = new Contact ("Mr", "Fred", "Bloggs", "01234 567890");
    myContacts.addContact(newContact1);
   
    Contact newContact2 = new Contact ("Mrs", "Sheila", "Bloggs", "09876 543210");
    myContacts.addContact(newContact2);
   
    //Output the contacts
    //Get the list name
    System.out.println(myContacts.getListName());
    System.out.print(myContacts.toString());
    System.out.println();
   
    //Prove the contacts list is a Singleton
    System.out.println("Attempt to get new contact list...");
    System.out.println("The Singleton will return the current instance... so it cannot be instaniated again.");
    ContactList theContacts = ContactList.getInstance();
    System.out.println(theContacts.getListName());
    System.out.println(theContacts.toString());
    System.out.println();
   
  }
View Full Code Here

TOP

Related Classes of Singleton.ContactList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.