score:0

your answer to the first question is correct.

what do they mean by variables exactly?

this tutorial page explains the exact meaning of variables.

the java programming language defines the following kinds of variables:

  1. instance variables (non-static fields) technically speaking, objects store their individual states in "non-static fields", that is, fields declared without the static keyword. non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words); the currentspeed of one bicycle is independent from the currentspeed of another.

  2. class variables (static fields) a class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. a field defining the number of gears for a particular kind of bicycle could be marked as static since conceptually the same number of gears will apply to all instances. the code static int numgears = 6; would create such a static field. additionally, the keyword final could be added to indicate that the number of gears will never change.

  3. local variables similar to how an object stores its state in fields, a method will often store its temporary state in local variables. the syntax for declaring a local variable is similar to declaring a field (for example, int count = 0;). there is no special keyword designating a variable as local; that determination comes entirely from the location in which the variable is declared — which is between the opening and closing braces of a method. as such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.

  4. parameters you've already seen examples of parameters, both in the bicycle class and in the main method of the "hello world!" application. recall that the signature for the main method is public static void main(string[] args). here, the args variable is the parameter to this method. the important thing to remember is that parameters are always classified as "variables" not "fields". this applies to other parameter-accepting constructs as well (such as constructors and exception handlers) that you'll learn about later in the tutorial.

in this case, the variables present are the instance fields n and m (type 1 above). the object of type y has n already defined in its class. since it extends x, it inherits the class member field m as well. a subclass inherits all of the public and protected members of its parent. therefore, the variables present in the object of type y are members m and n.

score:0

the object y of type y contains two variables; an int "m" and an int "n" output: 3, 4

score:1

i would say:

the object y has a nested member, called n and a derived member from its super-class, called m.


Related Query

More Query from same tag