
exception identifier required in java
#1
Posted 17 April 2008 - 05:00 AM
Register to Remove
#2
Posted 21 April 2008 - 01:34 AM
Edited by Tom Herry, 21 April 2008 - 01:35 AM.
#3
Posted 23 April 2008 - 12:04 PM
Again, as Tom says, you could declare it as static, or you could declare it within the main method.
Here are 3 ways of achieving what you want to do with this example:
class abc { static int a; public static void main(String[] args){ a = 10; System.out.println(a); } }
class abc { static int a = 10; public static void main(String[] args){ System.out.println(a); } }
class abc { public static void main(String[] args){ int a; a=10; System.out.println(a); } }
Additionally, "a = 10" is whats known as an assignment statement. These cannot be executed where you had yours, they need to be inside a method or constructor.
Hope that helps.
Edited by jpshortstuff, 23 April 2008 - 12:05 PM.
Proud Graduate of the TC/WTT Classroom
At weekends (GMT) I may not be able to reply promptly due to various commitments. Please be patient and I will respond as soon as I can.My help is free, however, if you wish to make a small donation to show appreciation and to help me continue the fight against Malware, then click here

Need help remembering those important computer maintenance tasks? Let SCars do it for you.

0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users