Thanks Evald Than you very much ya the mistake is constructor without arguments .again thanks
On Thu, Apr 16, 2009 at 12:46 PM, Ewald Ertl <[email protected]> wrote: > > Hi > > On Apr 16, 8:38 am, Ryu <[email protected]> wrote: > > Hi to all, > > Hope everyone is fine .Sorry i know this matter discussed > > lot of times in previous emails and i m reading all the emails and > > apply the techniques that had been discussed in those emails but since > > last week i am jammed at this homework . > > > > I read that create AddressImpl object in Person class I am > > trying this in different ways .First I did that Person class only > > implements MyOwn Interface and do something like this . I don't > > implements other interfaces because i think its only a matter of > > implements those interfaces methods and that is not difficult because > > they all have int and String type > > > > public class Person implements MyOwnInterface { > > > > AddressInterface address ; > > > > //Constructor > > public Person(AddressInterface address){ > > this.address = address; > > > > public AddressInterface getAddress(){ > > return address; > > } > > > > And in mian i tried > > > > Person person1 = new Person(new AddressImpl()); //You assign > > object that implements interface > > > > But this gives an error that > > can not find symbol > > symbol: constructor AddressImpl() > > > I do not see the AdressImpl class, but this error does not find > a constructor without any argument. > > > > Then i replace addressImpl with AddressInterface > > > > Person person1 = new Person( new AddressInterface()); > > > > But then it says > > AddressInterface is abstract ; can not be instantiated > > > The error says all -> only classes can be instantiated. > classes can be assigned to variables defined with the interface. > > > Then in Person class i try this > > > > public Person(){ > > address = new AddressImpl(); > > } > > > > and second time replace it with AddressInterface but i again get the > > above mentioned errors > > > > Then i extend the AddressImpl class > > > > public class Person extends AddressImpl implements MyOwnInterface > > { > > > > AddressInterface address ; > > > > public Person(int streetNumber, String streetName, String > > country, AddressInterface address){ > > super(streetNumber, streetName, country); > > this.address = address; > > } > > > > public AddressInterface getAddress(){ > > return address; > > } > > > > } > > > > But in main what i passed as a 4th parameter when i try to pass an > > instance of class(addressImpl) and interface (AddressInterface) it > > again prompt for an error . > > > The 4th parameter must be an instance of a class which is > implementing > AddressInterface. > > > i also try to create an instance in a single line in Person class > > like > > AddressInterface address = new AddressIntercae(); and also try > > AddressImpl address = new AddressImpl(); > > but the result is same ERRRRRRRRRooRRRs > Here again. Interfaces can not be instanciated. > > > > can some body help me why all this happen , where i m wrong , what > > mistake i m doing that i didn't figure out > > I think, that your problem is the missing constructor without any > arguments in > AddressImpl. Check the the source of AddressImpl.java or supply the > necessary > arguments you defined, when constructing a new instance of > AddressImpl. > > HTH > Ewald > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
