Could you change the static value declaration?(scjp07-95))
Gong James
Ranch Hand
Joined: Oct 15, 2001
Posts: 77
posted
0
Q95 Which of the following are true about this variable declaration? private static int i = 3; A The value of i may not be changed after it is assigned a value. B i may only be updated by a static method. C The value of i is shared among all instances of the class in which it is declared. D i may only be accessed within the class in which it is declared. the given ans is;CD. But I think the :BCD. Pls correct me if I am wrong.you always welcome the item.
lu v thuan
Ranch Hand
Joined: Oct 25, 2001
Posts: 32
posted
0
Originally posted by Gong James: Q95 Which of the following are true about this variable declaration? private static int i = 3; A The value of i may not be changed after it is assigned a value. B i may only be updated by a static method. C The value of i is shared among all instances of the class in which it is declared. D i may only be accessed within the class in which it is declared. the given ans is;CD. But I think the :BCD. Pls correct me if I am wrong.you always welcome the item.
Hi Gong James THe static keyword before var i informs that var i is shared by all intances of the class not showing where var i can be modified. Hope this help
Muhammad Farooq
Ranch Hand
Joined: May 08, 2001
Posts: 356
posted
0
The value of static member variable can be modified in any static/instance intializer block and/or static or non-static method, and constructor. Here is the demo: ======================================================== public class Reply { static int i = 10; public static void main(String args[]) { Reply r = new Reply(); r.try1(); try2(); System.out.println(i); } static { i = 20; System.out.println("The value of i is : " + i); } { i = 30; System.out.println("The value of i is : " + i); } Reply() { i = 40; System.out.println("The value of i is : " + i); } void try1(){ i = 50; System.out.println("The value of i is : " + i); } static void try2(){ i = 60; System.out.println("The value of i is : " + i); } } ======================================================== HTH --Farooq
Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Gong James
Ranch Hand
Joined: Oct 15, 2001
Posts: 77
posted
0
I didn't catch what you mean,you mean the B is right or wrong ?
Gong James
Ranch Hand
Joined: Oct 15, 2001
Posts: 77
posted
0
the ans B is wrong .This had been proved right. thank you very much,I agree with you. Thank you very much!!