Programming Concepts using Java, Quiz 1
Consider the following Java program. When the call stack reaches its maximum depth, which method will be at the top of the call stack?
class Example { public void methodA(int x) { if (x > 0) { methodB(x - 1); } } public void methodB(int y) { if (y > 0) { methodC(y - 1); } } public void methodC(int z) { if (z > 0) { methodA(z - 1); } }}
class TestCallStack { public static void main(String[] args) { Example e = new Example(); e.methodA(3); }}Consider the following Java program. When the call stack reaches its maximum depth, which method will be at the top of the call stack? class Example { public void methodA(int x) { if (x > 0) { methodB(x - 1); } } public void methodB(int y) { if (y > 0) { methodC(y - 1); } } public void methodC(int z) { if (z > 0) { methodA(z - 1); } } } class TestCallStack { public static void main(String[] args) { Example e = new Example(); e.methodA(3); } } Consider the Java code below. class Account { public void login() { System.out.println("Basic login"); } } class User extends Account { public void login() { super.login(); System.out.println("User login"); } public void login(String code) { System.out.println("User login with code: " + code); } } class Admin extends User { public void login() { super.login(); System.out.println("Admin login"); } public void login(String code) { System.out.println("Admin login with code: " + code); } } public class Test { public static void main(String[] args) { User obj = new Admin(); // LINE 1 obj.login(); obj.login("9999"); } } Choose the correct option. Consider the Java code given below. class Animal { private String name; public Animal(String n) { name = n; } public String toString() { return "Name: " + name; } } class Dog extends Animal { private String breed; public Dog(String n, String b) { //LINE 1 breed = b; } public String toString() { return super.toString() + ", Breed: " + breed; } } public class Test { public static void main(String[] args) { Animal dog = new Dog("Rocky", "Golden Retriever"); System.out.println(dog); } } Choose the correct option to be filled in place of `LINE 1` so that the output is: `Name: Rocky, Breed: Golden Retriever`