Advertisement
apl-mhd

OOP static counter

May 30th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class StudentInfo {
  4.  
  5.     int id;
  6.     String name;
  7.     static  String uni = "United International University ";
  8.  
  9.     static  int x=0;
  10.  
  11.     StudentInfo(int i, String nm){
  12.  
  13.         id = i;
  14.         name = nm;
  15. /*
  16.         System.out.println("Id: 0"+id);
  17.         System.out.println("Name: "+name);
  18.         System.out.println("University: "+uni);
  19.         System.out.println();
  20. */
  21.     }
  22.  
  23.     void display(){
  24.  
  25.         System.out.println("Id: 0"+id);
  26.         System.out.println("Name: "+name);
  27.         System.out.println("University: "+uni);
  28.         System.out.println();
  29.  
  30.     }
  31.  
  32.     StudentInfo(){
  33.  
  34.         x +=1;
  35.         System.out.println("Static: "+x);
  36.  
  37.     }
  38.  
  39.  
  40.  
  41.  
  42.     public static void main(String[] args) {
  43.  
  44.         StudentInfo  one = new StudentInfo();
  45.         StudentInfo  two = new StudentInfo();
  46.         StudentInfo  three = new StudentInfo();
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement