6 Replies - 419 Views - Last Post: 09 August 2017 - 02:19 PM Rate Topic: -----

#1 Glasir  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 86
  • Joined: 06-June 17

Accessing the other class' methods

Posted 09 August 2017 - 11:37 AM

Hello,

after you use class extends class such as below:
public class BanffMarathonRunner extends AddressBook {



How do I create a constructor in my program that access' the other program or class' methods?

I just need one method from my AddressBook, its the getHomeAddress. This is my code:
// Instance Fields
    private String firstName;
    private String lastName;
    private int    time;
    private int    year;

    // Constructor
    public BanffMarathonRunner(String fN, String lN, int t, int y, String hA) {
        this.firstName = fN;
        this.lastName  = lN;
        this.time      = t;
        this.year      = y;
        super.setHomeAddress(hA);
    }



I get the error: Implicit super constructor AddressBook() is undefined. Must explicitly invoke another constructor

Thank you for your recommendation

Is This A Good Question/Topic? 0
  • +

Replies To: Accessing the other class' methods

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13344
  • View blog
  • Posts: 53,121
  • Joined: 12-June 08

Re: Accessing the other class' methods

Posted 09 August 2017 - 11:40 AM

Have you looked at the keyword 'super'?
Was This Post Helpful? 0
  • +
  • -

#3 Glasir  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 86
  • Joined: 06-June 17

Re: Accessing the other class' methods

Posted 09 August 2017 - 11:52 AM

Yes, this is what I am looking into. I am not getting it to work or having a hard time understanding it..

My constructor worked fine, all of a sudden I had to access from another class and I am wondering if I need another new constructor or if I can use this one and how to use the super keyword.

This post has been edited by Glasir: 09 August 2017 - 11:52 AM

Was This Post Helpful? 0
  • +
  • -

#4 Glasir  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 86
  • Joined: 06-June 17

Re: Accessing the other class' methods

Posted 09 August 2017 - 12:13 PM

Ok I have fixed it now!
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13344
  • View blog
  • Posts: 53,121
  • Joined: 12-June 08

Re: Accessing the other class' methods

Posted 09 August 2017 - 12:18 PM

What did you do to understand or get the code to work?
Was This Post Helpful? 0
  • +
  • -

#6 Glasir  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 86
  • Joined: 06-June 17

Re: Accessing the other class' methods

Posted 09 August 2017 - 02:18 PM

I learned that super has to be the first statement in the constructor and you need to do it like this: super(...)
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13344
  • View blog
  • Posts: 53,121
  • Joined: 12-June 08

Re: Accessing the other class' methods

Posted 09 August 2017 - 02:19 PM

Hopefully that's helpful to someone in the future that has a similar question and stumbles upon this post! :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1