Advertisement
Guest User

Untitled

a guest
Mar 5th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.76 KB | None | 0 0
  1. public class Student{
  2.     private String name;
  3.     private int id;
  4.     private String address;
  5.    
  6.     public Student(){
  7.         name = "";
  8.         id = 0;
  9.         address = "";
  10.     }
  11.    
  12.     public String getName(){
  13.         return name;
  14.     }
  15.    
  16.     public int getID(){
  17.         return id;
  18.     }
  19.    
  20.     public String getAddress(){
  21.         return address;
  22.     }
  23.    
  24.     public void setName(String n){
  25.         name = n;
  26.     }
  27.    
  28.     public void setID(int i){
  29.         id = i;
  30.     }
  31.    
  32.     public void setAddress(String a){
  33.         address = a;
  34.     }
  35. }
  36.  
  37. public static void main(String[] args){
  38.     Student stu1 = new Student();
  39.     stu1.setName("Bob");
  40.     stu1.setID(10110);
  41.     stu1.setAddress("123 Main St");
  42.    
  43.     System.out.println("Name: " + stu1.getName());
  44.     System.out.println("ID: " + stu1.getID());
  45.     System.out.println("Address: " + stu1.getAddress());
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement