163k views
1 vote
In a java class, variables can be present both inside and outside of methods. question 9 options:

a. True
b. False

User Shavar
by
5.4k points

1 Answer

5 votes
The correct answer is: True

Step-by-step explanation:

Consider the following program:
class Main {
int a = 10;
public static void main(String[] args) {
add();
}

private static void add() {
int b = a+20;
System.out.println(b);
}
}


The output of the above program is 30. As you can see the variable a is declared outside the method, whereas variable b is declared inside the method.
User Timothy Rajan
by
5.1k points