Constructor


Java Code: class A { int a=10; int b; int c; A(int i) { b=i; } } public class C_onstructor { public static void main(String args[]) { A ob=new A(20); System.out.println("a "+ob.a);//result=10 System.out.println("b "+ob.b);//result=20 System.out.println("c "+ob.c);//result=0 ob.c=30; System.out.println("a "+ob.a);//result=10 System.out.println("b "+ob.b);//result=20 System.out.println("c "+ob.c);//result=30 } } mh_sh_highlight_all('java');
1)I created a class with 3 filed. I initialized a with value 10 at the point of definition.
I will initialize b with Constructor. what is the difference between two approaches

2)Before i used from ob.c=30;,value of c was 0. Did A(int i) cause that c=0
Posted On: Thursday 25th of October 2012 01:51:30 AM Total Views:  67
View Complete with Replies

RELATED TOPICS OF Java PROGRAMMING LANGUAGE