Analyze the following code and choose the best answer :
```
public class Foo {
private int x;
public static void main(String[] args) {
Foo foo = new Foo();
System.out.println(foo.x);
}
}```
a. Since x is private, it cannot be accessed from an object foo.
b. Since x is defined in the class Foo, it can be accessed by any method inside the class without using an object. You can write the code to access x without creating an object such as foo in this code.
c. Since x is an instance variable, it cannot be directly used inside a main method. However, it can be accessed through an object such as foo in this code.
d. You cannot create a self-referenced object; that is, foo is created inside the class Foo.
c (A) is incorrect, since x can be accessed by an object of Foo inside the Foo class. (B) is incorrect because x is non-static, it cannot be accessed in the main method without creating an object. (D) is incorrect, since it is permissible to create an instance of the class within the class. The best choice is (C).
You might also like to view...
What are some of the advantages and disadvantages for using HTML5 over HTML 4 markup?
What will be an ideal response?
Which partition type is installed as part of the Linux boot sector?
A. Primary B. Extended C. Logical D. Cache
A(n) ________ module stores procedures that are available to a specific form or report
Fill in the blank(s) with correct word
The extraction operator >> skips only all leading blanks when searching for the next data in the input stream.
Answer the following statement true (T) or false (F)