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()
Then i replace addressImpl with AddressInterface
Person person1 = new Person( new AddressInterface());
But then it says
AddressInterface is abstract ; can not be instantiated
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 .
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
can some body help me why all this happen , where i m wrong , what
mistake i m doing that i didn't figure out
and what should i do to solve this homework
Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---