With this class: public class myFunction { public int x = 7; public int y = 3; } 1. What are the class variables? 2. What are the instance variables? 3. What is the output from the following code: myFunction a = new myFunction(); myFunction b = new myFunction(); a.y = 5; b.y = 6; a.x = 1; b.x = 2; System.out.println("a.y = " + a.y); System.out.println("b.y = " + b.y); System.out.println("a.x = " + a.x); System.out.println("b.x = " + b.x); System.out.println("myFunction.x = " + myFunction.x);
1. What are the class variables? class variable is any variable declared with the static modifies. There are no class variables in the given code. 2. What are the instance variables? Variables x and y are instance variable. 3. What is the output from the following code: System.out.println("myFunction.x = " + myFunction.x); This lines gives compile time error. Because x is not a class variable to access directly with class name. Output of the code other than the above line is a.y = 5 b.y = 6 a.x = 1 b.x = 2
Get Answers For Free
Most questions answered within 1 hours.