public class Student
{
private String name;
private String rollno;
private int age;
//Constructor
public Student(String name,String rollno,int age)
{
this.name=name;
this.rollno=rollno;
this.age=age;
}
//Method
public void display()
{
System.out.println("Name: "+this.name);
System.out.println("Roll No: "+this.rollno);
System.out.println("Age: "+this.age);
}
}
////////////////////////////////////////////////////////////////
public class StudentTest
{
public static void main(String[] args)
{
Student s1= new Student("John","A100",22);
Student s2= new Student("Abhi","5S0",18);
s1.display();
s2.display();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter