import java.io.*; class Student { private int roll_no; private String name; void get_data(String name,int roll_no) { this.name=name; this.roll_no=roll_no; } void display() { System.out.print("\nStudent Details: "); System.out.print("\nName: "+name); System.out.print("\nRoll_no: "+roll_no); } } class ClassDemo { public static void main(String s[]) throws Exception { Student s1=new Student(); Student s2=new Student(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nEnter Name: "); String name = br.readLine(); System.out.print("\nEnter Roll no: "); int roll_no = Integer.parseInt(br.readLine()); s1.get_data(name,roll_no); s1.display(); System.out.println(); } }
Output![]()
Nice Blog!
ReplyDeletegood example
ReplyDeletethanx for post