Java program to print student details using constructor

class Student_Details{	
  int roll_no;  
  String name, classno, gender; 
   Student_Details(int roll, String n, String c) {
	roll_no = roll ; 
	name = n;
	classno = c;
  }  	
  void display(){
	System.out.println("My name is "+name+", I study in "+classno+"
 class and my roll number is "+roll_no);
  }	 
  public static void main(String arg[]){
    Student_Details sd1 = new Student_Details(2, "James", "XIIth");
    Student_Details sd2 = new Student_Details(25, "Alex", "IXth");
    Student_Details sd3 = new Student_Details(1, "Michele", "XIth");	
    
   	 sd1.display();  
     sd2.display();
     sd3.display();  
  }	      
} 

Output:

Java program to print student details using constructor

Leave a Reply

Your email address will not be published. Required fields are marked *