Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8958325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:11:09+00:00 2026-06-15T15:11:09+00:00

I dont expect you to read the whole code. If you copy and paste

  • 0

I dont expect you to read the whole code. If you copy and paste it in your IDE you should find the issue.
I’m new to Java and this code is eating up my time because of this constructor issue.
All in all the code works fine but doesnt return the string reprsentation of objects

public class TestContact {

public static void main(String[] args) {

    // Juiste invoer begins with 0 and 9 digits
    Phone vasteTel1 = new Phone("027261747", "FIX");
    // wrong fix phone
    Phone vasteTel2 = new Phone("27261447", "FIX");

    // Juiste invoer begins with 0 and 10 digits
    Phone mobieleTel1 = new Phone("0495556080", "MOBIELE");
    // // wrong mobile phone
    Phone mobieleTel2 = new Phone("10495557841", "MOBIELE");

    Contact contact1 = new Contact("Joske Ergens", "mobiele",
            "jos.ergens@where.com", "0495558041");
    Contact contact2 = new Contact("Joseline Peremans", "mobiele",
            "joseline.peremans@where.com", "024596247");

    System.out.println("NUMMER " + vasteTel1.getNummer() + "\nSOORT: "
            + vasteTel1.getSoort() + "\nGELDIG NUMMER ?: "
            + vasteTel1.isGeldigNummer() + "\n");
    System.out.println("NUMMER " + vasteTel2.getNummer() + "\nSOORT: "
            + vasteTel2.getSoort() + "\nGELDIG NUMMER ?:"
            + vasteTel2.isGeldigNummer() + "\n");
    System.out.println("NUMMER " + mobieleTel1.getNummer() + "\nSOORT: "
            + mobieleTel1.getSoort() + "\nGELDIG NUMMER ?: "
            + mobieleTel1.isGeldigNummer() + "\n");
    System.out.println("NUMMER " + mobieleTel2.getNummer() + "\nSOORT: "
            + mobieleTel2.getSoort() + "\nGELDIG NUMMER ?: "
            + mobieleTel2.isGeldigNummer() + "\n");

    System.out.println(contact2);

}

}

public class Contact extends ContactGegevens {

ContactGegevens gegevens;
String naam;

public Contact() {

}

public Contact(String naam, String soort, String mail, String nummer) {
    this.naam = naam;
    gegevens = new ContactGegevens(getNummer(), getSoort(), getEmail());

}

public void toonInfo() {

}

public String toString() {
    return "NAAM: " + naam + "|\n" + gegevens.getNummer();
}

}

public class ContactGegevens extends Phone {

private String eMail;
private Phone gsm;
private Phone telefoon;

public ContactGegevens() {

}

public ContactGegevens(String nummer, String soort, String email) {
    super(nummer, soort);
    this.eMail = email;
    gsm = new Phone(getNummer(), getSoort());
    telefoon = new Phone(getNummer(), getSoort());

}

public String getEmail() {
    return eMail;

}

public Phone getGsm() {
    return gsm;

}

public Phone getTelefoon() {
    return telefoon;
}

public String toString() {
    // return email adress vast foon, gsm
    return "" + eMail + "  " + gsm;
}

}

public class Phone {

private static final int LENGTE_MOBIEL = 10;
private static final int LENGTEVAST = 9;

private String nummer;
private String soort;

public Phone() {

}

public Phone(String nummer, String soort) {
    this.nummer = nummer;
    this.soort = soort;
}

public String getNummer() {

    return nummer;
}

public String getSoort() {

    return soort;
}

public boolean isGeldigNummer() {
    if ((nummer.startsWith(nummer, 0) && nummer.length() == LENGTE_MOBIEL))
        return true;
    else if ((nummer.startsWith(nummer, 0) && nummer.length() == LENGTEVAST))
        return true;

    else
        return false;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:11:11+00:00Added an answer on June 15, 2026 at 3:11 pm

    Your bug is actually here:

    public Contact(String naam, String soort, String mail, String nummer) {
        this.naam = naam;
        gegevens = new ContactGegevens(getNummer(), getSoort(), getEmail());
    }
    

    You’re setting the gegevens object as a new ContactGegevens, and calling the getters of your object, which will return all nulls as its fields have not been set. Adapt as follows:

    public Contact(String naam, String soort, String mail, String nummer) {
        this.naam = naam;
        gegevens = new ContactGegevens(nummer, soort, mail);
    }
    

    Furthermore, you’re extending and composing the same classes, please take a look at some Object Orientation books… You should

    a. Either extend the ContactGegevens class, and call the super(…) constructor and not make it a field.
    b. Either not extend it and compose Contact and ContactGegevens by making the ContactGegevens a field like you’re doing now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not an expert in Java and I'm pretty new to the whole concept
I dont know if this is possible. In SSIS Derived column transformation, can you
I dont think this is possible in c# but ill post it anyway. Given
As a maintenance issue I need to routinely (3-5 times per year) copy a
For Example: If I need to read a multiple line input like(and I dont
I'm new to Java development so please bear with me. Also, I hope I'm
I'm really new at network-programming, so I hope this isn't a complete Newbie-question. I
I've been fighting with this issue for a while now. The matter is that
I've only started learning Java about 3 months ago and this is my first
I have read a lot about Java classloaders, but so far I have failed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.