Programming Concepts using Java, End Term
Consider the code given below.
class Shared { static int count = 2000;}class Subtractor extends Thread { public void run() { for (int i = 0; i < 1000; i++) { Shared.count--; } }}public class Test { public static void main(String[] args) throws InterruptedException { Thread t1 = new Subtractor(); Thread t2 = new Subtractor(); t1.start(); t2.start(); t1.join(); t2.join(); System.out.print(Shared.count); }}Choose the correct option.
Consider the code given below. class Shared { static int count = 2000; } class Subtractor extends Thread { public void run() { for (int i = 0; i < 1000; i++) { Shared.count--; } } } public class Test { public static void main(String[] args) throws InterruptedException { Thread t1 = new Subtractor(); Thread t2 = new Subtractor(); t1.start(); t2.start(); t1.join(); t2.join(); System.out.print(Shared.count); } } Choose the correct option. Consider the following Java code that uses chained exceptions. class PaymentException extends Exception { public PaymentException(String message) { super(message); } } class OrderProcessingException extends Exception { public OrderProcessingException(String message) { super(message); } } class OrderService { public void placeOrder() throws OrderProcessingException { try { // if(payment fails) throw new PaymentException("Payment not done"); // else process the order } catch (PaymentException e) { OrderProcessingException oe = new OrderProcessingException ("Order Failed"); oe.initCause(e); throw oe; } } } public class Test { public static void main(String[] args) { OrderService orderService = new OrderService(); try { orderService.placeOrder(); } catch (OrderProcessingException e) { System.out.println(e.getMessage()); System.out.println("Root cause: " + e.getCause().getMessage()); } } } Which of these could be the output of this code? Consider the two Java files given below. **Animal.java:** package creatures; class Animal { private String name; private String habitat; private int legs; // Constructor to initialize instance variables public String getName(String name) { return name; } private String getHabitat(String habitat) { return habitat; } protected int getLegs(int legs) { return legs; } public int showLegs(int legs) { return getLegs(legs); } } class Bird extends Animal { public void info() { System.out.println("This is a Bird."); } public void displayHabitat() { System.out.println("Bird's habitat: " + getHabitat("Trees")); } } **Test.java:** package creatures; public class Test { public static void main(String[] args) { Animal myAnimal = new Animal(); System.out.println("Number of legs: " + myAnimal.showLegs(4)); System.out.println(myAnimal.getHabitat("Forest")); // LINE 1 System.out.println(myAnimal.getLegs(4)); // LINE 2 } } Choose the correct option.