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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:05:35+00:00 2026-05-31T23:05:35+00:00

I have a student class and every student instance created needs to be stored

  • 0

I have a student class and every student instance created needs to be stored in an array.attributes can be given in program or read from user input.how do I extend my main() method to store it? i am stuck .

Here is my student class code:

public class student {

    int   studentID;
    String studentName,gender,course;
 /** set the student name
  * @param studentName
 */
 public  void        setName(String studentName){
this.studentName = studentName;
 }
  /**
  * set student ID number
  * @param studentID 
   */
   public  void        setNewId(int studentID){
   this.studentID = studentID;
  }
   /**
   * Set student gender
   * @param gender 
   */
   public void setGender(String gender){
  this.gender = gender;
 }
 /**
  * set the course
  * @param course 
  */
   public  void        setCourse(String course){
   this.course = course;
 }
 /**
  *Gets the Student's ID Number.
  *@return IdNumber Student ID Number.
  */
  public  int      getIdNumber(){
return studentID;
 }

  /**
  *Gets the Student's Name.
  *@return studentName Student Name.
  */
 public  String      getName(){
return studentName;
 }
 /**
  * Get student gender
  * @return 
   */
 public String getGender(){
  return gender;
 }
 /**
  *Gets the Student's Course.
  *@return course Student Course.
  */

  public  String     getCourse(){
return course;
  }
  /**
  *Prints Student Informations.
  *@return Student ID Number, name, gender and course.
    */

  public void printStudent(){
 System.out.print(studentID+""+studentName+""+gender+""+course);
}
}

And here is my main class with main() method that needs the array:

public class SMSMain {
    /**
     * 
     * @param args
     */
    public static void main(String[] args) {
    // Create an instance of student object

    student a = new student();
    a.studentName = "Maria";
    a.studentID = 1236;
    System.out.println("Student Name:" + a.studentName);
    System.out.println("Student ID:" + a.studentID);
}
}
  • 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-05-31T23:05:36+00:00Added an answer on May 31, 2026 at 11:05 pm

    You need to initiate the array and create objects within loop.

       Student[] students;
        System.out.println("Enter number of students :");
    
    
        DataInputStream in = new DataInputStream(System.in);
        int n = in.readInt();
        students = new Student[n];
        for(int i=0; i<n ;i++) {
            students[i] = new Student();
            System.out.println("Name:");
            students[i].setName(in.readLine());
            System.out.println("Id:");
            students[i].setNewId(in.readInt());
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of custom class Student objects. CourseStudent and ResearchStudent both inherit
I have two classes, a Teacher class and a Student class. In my program
Let's say I have a class of 30 students and want generate every possible
I have two student objects. class Student{ int physics; int english; int chemistry; }
I have two scaffold-generated Models, student and class . They have a many-to-many relationship
I have class Student { public List<Degree> Degrees {get;set;} } class Degree { public
I have an organization that has clients and students, every student begins as a
I have a Store class which is an array of Person; I have a
I'm in a CS101 class at my school using C++. I have a program
Students can be in many different classes. Each class has many different student. A

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.