public static void main(String[] args) { Person[] people = new Person[2]; people[0] = new Emplyee("Harry Hacker", 5000, 1989, 10, 1); people[1] = new Student("Maria Morris", "computer science"); for (Person p : people) { System.out.println(p.getName() + "," + p.getDescription()); } for (Person p1 : people) { String description = p1.getDescription(); System.out.println(description); } }
public static void main(String[] args) { Person[] people = new Person[2]; // fill the people array with Student and Employee objects people[0] = new Employee("Harry Hacker", 50000, 1989, 10, 1); people[1] = new Student("Maria Morris", "computer science"); // print out names and descriptions of all Person objects for (Person p : people) System.out.println(p.getName() + ", " + p.getDescription()); }
/** @param args */ public static void main(String[] args) { Person julie = new Julie(); Person pedro = new Pedro(); julie = new Trousers(julie); julie = new Shoes(julie); julie = new Pullover(julie); Trousers t = new Trousers(pedro); Pullover p = new Pullover(t); Underpants u = new Underpants(p); System.out.println(u.getDescription() + u.clothingCost()); System.out.println(julie.getDescription()); }
public void testBasic() throws Exception { LdapFactoryHelper helper = (LdapFactoryHelper) lookup(LdapFactoryHelper.ROLE); PersonLdapFactory.setHelper(helper); InitialDirContext context = apacheDs.getAdminContext(); context.addToEnvironment(Context.OBJECT_FACTORIES, PersonLdapFactory.class.getName()); context.addToEnvironment(Context.STATE_FACTORIES, PersonLdapFactory.class.getName()); LdapName name = new LdapName("uid=trygvis,dc=test"); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- try { context.unbind(name); } catch (NamingException e) { // ignore } Person person = new Person(); person.setName("Trygve"); context.bind(name, person); Object o = context.lookup(name); assertEquals(Person.class, o.getClass()); person = (Person) o; assertEquals("Trygve", person.getName()); assertEquals(null, person.getDescription()); context.close(); }
@Test public void correctDescription() { assertEquals("Julie, Trousers, Shoes, Pullover", p1.getDescription()); }