Menu

Post image 1
Post image 2
1 / 2
0

Common Errors While Using Global Variables in Java Programming

DEV Community·PRIYA K·24 days ago
#O8jM8BID
Reading 0:00
15s threshold

1.Error: Accessing Instance Global Variable in Static Method class GlobalError1 { int cost = 1000 ; // instance global variable public static void main ( String args []) { System . out . println ( cost ); // ERROR } } Enter fullscreen mode Exit fullscreen mode Output non-static variable cost cannot be referenced from a static context class GlobalError1 { int cost = 1000 ; public static void main ( String args []) { GlobalError1 obj = new GlobalError1 (); System . out . println ( obj . cost ); } } Enter fullscreen mode Exit fullscreen mode 2.Error: Using Object for Static Variable class GlobalError2 { static String name = "Scooby" ; public static void main ( String args []) { System . out . println ( namee ); // spelling error } } Enter fullscreen mode Exit fullscreen mode Output Cannot find symbol class GlobalError2 { static String name = "Scooby" ; public static void main ( String args []) { System . out .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More