Can someone help me with this JAVA problem: Given public class Q7_10 { private boolean x; int y; static String s; void imethod() {} } Which of the following statements are incorrect? Q7_10 f= new Q7_10(); a) System.out.println(f.y); b) Q7_10.smethod(); c) Q7_10.imethod(); d) System.out.println(Q7_10.s); c) System.out.println(Q7_10.x); I'm done with all other problems but stuck on this one. Hoping for some explanation would be helpful too. I hate taking programming language and information classes online since there's no one teaching you, it seems like you're reading and trying to learn yourself. (only course offer) thanks,
Q7_10.smethod(); - There is no smethod Q7_10.imethod(); - The imethod is not static System.out.println(Q7_10.x); - x is not static and if it was static its private variable
a) Maybe wrong. I would consider it bad code. Since it is not given a scope, it is package scope. Only classes in the same package can access the variable. b) Wrong. There is no smethod. c) Wrong. It is trying to call imethod statically and imethod is not declared static. d) Maybe wrong. It can access the variable statically since it is declared static. However only classes in the same package can access the variable. e) Wrong. It is trying to access a not static variable statically. B, C, and E are definitely wrong. A and B are wrong if the class calling them is in a different package. Overall its a pretty poor example.