Advertisement
Guest User

Untitled

a guest
Jan 31st, 2011
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. package jar2;
  2.  
  3.  
  4. /**
  5.  *
  6.  * @author Janith
  7.  */
  8.  
  9. class Student {
  10.     private String name;
  11.     private String ditno;
  12.     private String addr;
  13.  
  14.     public Student(String n, String d, String a)
  15.     {
  16.         this.name = n;
  17.         this.ditno = d;
  18.         this.addr = a;
  19.     }
  20.  
  21.     public String getName() { return this.name; }
  22.     public String getAddress() { return this.addr; }
  23.     public String getDIT() { return this.ditno; }
  24.  
  25.     public void setName(String n) { this.name = n; }
  26.     public void setAddress(String a) { this.addr = a; }
  27.     public void setDIT(String d) { this.ditno = d; }
  28.  
  29.     public String getDetails ()
  30.     {
  31.         return "I'm a student.\nMy name is "+this.name+".\nI'm from "+this.addr+".\nMy DIT no is "+this.ditno+". ";
  32.     }
  33. }
  34.  
  35. public class Test {
  36.  
  37.     public static void main(String[] args) {
  38.         Student s1 = new Student("Heshan Perera", "DIT/10/C1/0021", "23, Main Road, Welisara");
  39.         Student s2 = new Student("Inosh Perera", "DIT/10/C1/0064", "53, 1st Lane, Ja-Ela");
  40.  
  41.        
  42.  
  43.         System.out.println(s1.getName());
  44.         System.out.println(s1.getDIT());
  45.         System.out.println(s1.getAddress());
  46.  
  47.         System.out.println(s2.getName());
  48.         System.out.println(s2.getDIT());
  49.         System.out.println(s2.getAddress());
  50.  
  51.         System.out.println(s1.getDetails());
  52.         System.out.println(s2.getDetails());
  53.  
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement