Advertisement
Didikpry

Static1

May 23rd, 2019
2,553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MyClass {
  2.     public static void main(String args[]){  
  3.     Duck d;
  4.     d = new Duck(4);
  5.     d = new Duck(6);
  6.     d = new Duck(8);
  7.  
  8.         System.out.println(d.getCount());
  9.     }
  10. }
  11. class Duck{
  12.     private int size;
  13.     private static int duckCount= 0;
  14.  
  15.     public Duck(int size){
  16.         this.size = size;
  17.         duckCount++;
  18.     }
  19.    
  20.     public int getCount(){
  21.         return duckCount;
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement