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 9195237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:35:09+00:00 2026-06-17T21:35:09+00:00

I am trying to print the first element on the two arrays in my

  • 0

I am trying to print the first element on the two arrays in my Athlete class, country and name. I also need to create a object that simulates three dive attemps an athlete had (that is initially set to zero). I am new to OOP and I dont know how to go abouts doing this in my main… as far as constructors go. This is what i have done so far…

this is the main:

import java.util.Random;
import java.util.List;


public class Assignment1 {
public static void main(String[] args) {
            Athlete art = new Athlete(name[0], country[0], performance[0]);   
    }
}

I just really am not sure what to do…

And this is the class with the arrays.

 import java.util.Random;
 import java.util.List;

 public class Athlete {

public String[] name = {"Art", "Dan", "Jen"};
public String[] country = {"Canada", "Germant", "USA"};
    //Here i would like to create something that would be representing 3 dive attemps  (that relate to dive and score. eventually.)

 Athlete(String[] name, String[] country, Performance[] performance) {
    this.name = name;
    this.country=country;
    this.performance=performance;

}



public Performance Perform(Dive dive){
    dive.getDiveName();
    return null;        
}

public String[] getName() {
    return name;
}

public void setName(String[] name) {
    this.name = name;
}

public String[] getCountry() {
    return country;
}

public void setCountry(String[] country) {
    this.country = country;
}

    }

thanks in advance for any help and input!
btw there is other classes too, just not relevant atm..

  • 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-17T21:35:10+00:00Added an answer on June 17, 2026 at 9:35 pm

    First, as for your Athlete class, you can remove your Getter and Setter methods since you have declared your instance variables with an access modifier of public. You can access the variables via <ClassName>.<variableName>.

    However, if you really want to use that Getter and Setter, change the public modifier to private instead.

    Second, for the constructor, you’re trying to do a simple technique called shadowing. Shadowing is when you have a method having a parameter with the same name as the declared variable. This is an example of shadowing:
    ----------Shadowing sample----------
    You have the following class:

    public String name;
    
    public Person(String name){
        this.name = name; // This is Shadowing
    }
    

    In your main method for example, you instantiate the Person class as follow:
    Person person = new Person("theolc");

    Variable name will be equal to "theolc".
    ----------End of shadowing----------

    Let’s go back to your question, if you just want to print the first element with your current code, you may remove the Getter and Setter. Remove your parameters on your constructor.

    public class Athlete {
    
    public String[] name = {"Art", "Dan", "Jen"};
    public String[] country = {"Canada", "Germany", "USA"};
    
    public Athlete() {
    
    }
    

    In your main method, you could do this.

    public static void main(String[] args) {
           Athlete art = new Athlete();   
    
           System.out.println(art.name[0]);
           System.out.println(art.country[0]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create my first custom Print Dialog in C#. I found
I am trying to create a Hash that has as its value an array.
this is something that's been bugging me for the past two hours. I'm trying
So here is the problem: I am trying to create dynamic buttons that have
I am trying to calculate the distance between the first GPS point stored in
Im trying print Excel file data on a page. To do it i used
Im trying to print the realtime output based on user input for a search.
I'm trying to print a number of '+' characters followed by a number of
I'm trying to print a large string to alivepdf. I'm splitting the string by
I'm trying to print out a list of products on a page. This is

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.