Class Program

Write a program in java to show use of class

 
public class StudentInfo 
{
 String name,add;
 int rollno;
 void setname(String n)
 {
  name=n;
 }
 void setroll(int roll)
 {
  rollno=roll;
 }
 void setadd(String addr)
 {
  add=addr;
 }
 void display()
 {
  System.out.println("Name of student: "+name);
  System.out.println("Address of student: "+add);
  System.out.println("RollNo of student: "+rollno+"\n");
 }
}

public class StudentDemo 
{
 public static void main(String[] args) 
 {
  StudentInfo s= new StudentInfo();
  s.setname("John");
  s.setroll(15);
  s.setadd("Ahmedabad");
  s.display();
 
  StudentInfo s1= new StudentInfo();
  s1.setname("Reema");
  s1.setroll(07);
  s1.setadd("Surat");
  s1.display();
 }
}

Output

0 comments:

Post a Comment