Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class scopeRule //Line 1 { //Line 2 static double intRate = 0.055; //Line

ID: 3779823 • Letter: P

Question

public class scopeRule                                //Line 1
{                                                     //Line 2
    static double intRate = 0.055;                    //Line 3
    static String name;                               //Line 4
    static int t;                                     //Line 5

    public static int main(String[] args)             //Line 6
    {                                                 //Line 7
        int first;                                    //Line 8
        double u, t;                                  //Line 9
        String str;                                   //Line 10
        //...                                         //Line 11
    }                                                 //Line 12

    public static int first(int x, int y)             //Line 13
    {                                                 //Line 14
        int t;                                        //Line 15
        //...                                         //Line 16
    }

    public static double salary;                      //Line 17

    public static void funcOne(int first, double x)   //Line 18
    {                                                 //Line 19
        char ch;                                      //Line 20
        int y;                                        //Line 21
    
        //block one                                   //Line 22
        {                                             //Line 23
            int u = 18;                               //Line 24
            //...                                     //Line 25
        } //end block one                             //Line 26
    }                                                 //Line 27
}                                                     //Line 28

i) Which of the following identifiers seen in the accompanying figure is visible in block one?

name (Line 4)

t (Line 9)

local variables of main

x (Line 13)

ii.) Which of the following identifiers seen in the accompanying figure is NOT visible in method funcOne?

a. intRate (Line 3)

b. u (Line 24)

salary (Line 17)

first (Line 13)

iii.)

Which of the following identifiers seen in the accompanying figure is visible in method first?

a. intRate (Line 3)

b. local variables of method funcOne

c. u (Line 24)

d. first (Line 8)

iv.)

Which of the following identifiers seen in the accompanying figure is visible in main?

a. t (Line 5)

b. salary (Line 17)

c. local variables of method funcOne

d. All identifiers are visible in main.

v.) Which of the following is an example of a local identifier in the example seen in the accompanying figure?

a. intRate (Line 3)

b. name (Line 4)

c. salary (Line 17)

d. t (line 15)

a.

name (Line 4)

b.

t (Line 9)

c.

local variables of main

d.

x (Line 13)

Explanation / Answer

Answer :

i) Which of the following identifiers seen in the accompanying figure is visible in block one?

a) name (it is class variable so it is visible to block 1)

b) t (it is main method variable, so it is not visible outside of that method)

c) local variables of main (it is main method variables, so it is not visible outside of that method)

d) x (it is a parameter to first method, so it is not visible to block one)

ii) Which of the following identifiers seen in the accompanying figure is NOT visible in method funcOne?

a,b,c) All are visible in funcOne

d) first (it is method which is not a variable so it is not visible).

iii) Which of the following identifiers seen in the accompanying figure is visible in method first?

a) intRate (it is visible in method first)

b) local variables of method funcOne (not visible in method first)

c) u (it is variable of method funcOne so it is not visible)

d) first (it is variable of method main. so it is not visible)

iv) Which of the following identifiers seen in the accompanying figure is visible in main?

a) t (it is class variable so it is visible in main)

b) salary (it is also class variable ,so it is visible in main)

c)  local variables of method funcOne (these are not visible to main, these are local to method funcOne)

d) All identifiers are visible in main. (False , all are not visible in main)

v) Which of the following is an example of a local identifier in the example seen in the accompanying figure?

a) intRate (it is a class variable not a local variable)

b) name (it is a class variable not a local variable)

c) salary (it is a class variable not a local variable)

d) t (it is local variable to method first)