HI,
public class
test {
drink d;
public static void main(
String a[])
{
test b=new test();
test c=new test();
b.d=drink.tea;
c.d=drink.tea;
System.out.println(b.d.getval());
System.out.println(c.d.getval());
}
}
enum drink
{
coffee(5),tea(6);
int val;
drink(int val){this.val=val;}
int getval(){return val++;}
}
O/p is 6,7
My doubt is that the in int val is nonstatic and the o/p should be 6,6
as for each assignment the value of the obejct is got from the enum declaration. And in my code there are two differnt object.
please help.