What is the result of compiling and executing the following class?
1: public class MyClass { 2: int birds = 10; 3: public static void main(String[] data) { 4: int trees = 5; 5: System.out.print(trees + birds); 6: } 7: }
A.
The code does not compile because of line 5, making Option A the correct answer.
The main()
method is static and does not have access to any class instance variables.
The birds variable is not static and requires a class instance variable to access.
The code does not compile when the static method attempts to access a non-static variable without an instance of the class.