method over ridding
Mon Jul 08 2024 16:10:29 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
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();
}
}
content_copyCOPY
Comments