Ask Question
7 September, 23:24

Write a Student class in Java which has a name, id_number, year (e. g. 2) and

programme_code (e. g. ECE) as member variables. Add a constructor to your class

and a display () method, which prints out all information relating to a Student.

+5
Answers (1)
  1. 7 September, 23:50
    0
    Following are the code in java

    public class Student

    {

    / / member variables

    String name;

    String id_number;

    int year;

    String programme_code;

    / / default constructor

    public student () / /default constructor

    {

    name="san";

    id_number="12";

    year = 2010;

    programme_code="ECE";

    }

    / / method to display the member variables of the Student

    public void display () / / dispaly the value

    {

    System. out. println ("Name is : "+name);

    System. out. println ("ID is : "+id_number);

    System. out. println ("Year is : "+year);

    System. out. println ("Programme code is : "+programme_code);

    }

    public static void main (String[] args) / / Main method

    {

    Student ob=new Student ();

    ob. display (); / / calling the method display

    }

    }

    Explanation:

    In this we create a class "student " name, id_number, year and programme_code are the variable after that create a default constructor and initialize the variable and finally display the variable. In the main method we create a object of student class i. e ob, and call display method with object ob.

    Output:

    Name is : san

    ID is : 12

    Year is : 2010

    Programme code is : ECE
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a Student class in Java which has a name, id_number, year (e. g. 2) and programme_code (e. g. ECE) as member variables. Add a ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers