Programming Concepts using Java, End Term
Consider the Java code given below.
1 class ClassOne{ 2 public void methodOne(){ 3 // ... 4 } 5 public void methodTwo(){ 6 // ... 7 methodOne(); 8 // ... 9 }10 }11 class ClassTwo{12 public static void methodThree(){13 // ...14 ClassOne c = new ClassOne();15 c.methodTwo();16 // ...17 }18 public static void main(String[] args) {19 // ...20 methodThree();21 }22 }During execution of Line 8 in the above code, the activation record of which method is at the top of the stack of activation records?
Consider the Java code given below. 1 class ClassOne{ 2 public void methodOne(){ 3 // ... 4 } 5 public void methodTwo(){ 6 // ... 7 methodOne(); 8 // ... 9 } 10 } 11 class ClassTwo{ 12 public static void methodThree(){ 13 // ... 14 ClassOne c = new ClassOne(); 15 c.methodTwo(); 16 // ... 17 } 18 public static void main(String[] args) { 19 // ... 20 methodThree(); 21 } 22 } During execution of Line 8 in the above code, the activation record of which method is at the top of the stack of activation records? Consider the following code. Consider the following code. class Equipment implements Cloneable{ String type; // Constructor // Accessor method getType() // Mutator method setType() public Equipment clone() throws CloneNotSupportedException{ return (Equipment)super.clone(); } } class Lab implements Cloneable{ Equipment eqp; String name; // Constructor // Mutator method setName() public Lab clone() throws CloneNotSupportedException{ Lab lb = (Lab)super.clone(); lb.eqp = lb.eqp.clone(); return lb; } public String toString(){ return eqp.getType() + ":" + name; } } public class Test { public static void main(String[] args) { Lab lb1 = new Lab(new Equipment("Computer"), "Computer"); try{ Lab lb2 = lb1.clone(); lb2.eqp.setType("Milling Machine"); lb2.setName("Mechanical"); System.out.println(lb1); System.out.println(lb2); } catch(Exception e){ System.out.println(e); } } } What will the output be? Consider the code given below class Animal{ public void legs(){ System.out.println("Number of legs are not known"); } public void wings(){ System.out.println("Wings may exist"); } } class Dog extends Animal{ public void legs(){ System.out.println("Four legs"); } } class Ostrich extends Animal{ public void legs(){ System.out.println("Two legs"); } public void wings(){ System.out.println("Two wings"); } } public class Test{ static void show(Animal[] a){ for(int i = 0; i < a.length; i++){ a[i].legs(); a[i].wings(); } } public static void main(String[] args){ Animal[] a = {new Dog(), new Ostrich()}; // LINE 1 show(a); } } Choose the correct option.