Variables can be divided into four categories static stackdy
Variables can be divided into four categories: static, stack-dynamic, explicit heap-dynamic, and implicit heap-dynamic. For each variable in the Java class below, specify which category it belongs to. Include both named variables and anonymous variables in your answer. public class Test {private static String ext = \".gif\"; public static void main(String[] args) {String file = \"demo\"; NameBuilder builder = new NameBuilder(ext); System.out.println(builder.buildName(file));}
Solution
In the given class
1) ext is a static variable of string type as its defined using static keyword.
private static String ext = \".gif\";
2) At line System.out.println(builder.buildName(file), here file is an stack dynamic variable as stack dynamic variable come into existence when we call a function, they are mostly in parameter list and temporary.
3) builder is heap dynamic at line NameBuilder buikder = new NameBuilder(ext) as heap dynamic variables are those which are created using new keyword.
