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 Java code given below. class Product { private String productName; public Product(String pn) { productName = pn; } public Product(Product p) { this.productName = p.productName; } public void setProductName(String pn) { productName = pn; } public String getProductName() { return productName; } } public class InventoryTest { public static void main(String[] args) { Product p1 = new Product("Laptop"); Product p2 = new Product(p1); Product p3 = p1; p1.setProductName("Smartphone"); System.out.println(p1.getProductName()); System.out.println(p2.getProductName()); System.out.println(p3.getProductName()); } } What will the output be? Consider the Java code given below. class Shape { public void draw() { System.out.println("Drawing a generic shape."); } public void area() { System.out.println("Calculating area of the shape."); } } class Circle extends Shape { public void draw() { System.out.println("Drawing a circle."); } } class Square extends Shape { public void draw() { System.out.println("Drawing a square."); } } public class ShapeApp { static void describe(Shape sh) { sh.draw(); sh.area(); } public static void main(String[] args) { Shape circle = new Circle(); Shape square = new Square(); describe(circle); describe(square); } } Choose the correct option.