Programming Concepts using Java, End Term
Consider the Java code given below, and answer the question that follows:
abstract class Operation implements Runnable { static int total = 10;}class Operation1 extends Operation { public void run() { if (total != 8) { total = total - 3; } }}class Operation2 extends Operation { public void run() { if (total != 7) { total = total - 2; } }}public class RaceConditionDecrement { public static void main(String[] args) { Operation op1 = new Operation1(); Operation op2 = new Operation2(); Thread t1 = new Thread(op1); Thread t2 = new Thread(op2); t1.start(); t2.start(); System.out.println(Operation.total); }}Choose the correct option.
Consider the Java code given below, and answer the question that follows: abstract class Operation implements Runnable { static int total = 10; } class Operation1 extends Operation { public void run() { if (total != 8) { total = total - 3; } } } class Operation2 extends Operation { public void run() { if (total != 7) { total = total - 2; } } } public class RaceConditionDecrement { public static void main(String[] args) { Operation op1 = new Operation1(); Operation op2 = new Operation2(); Thread t1 = new Thread(op1); Thread t2 = new Thread(op2); t1.start(); t2.start(); System.out.println(Operation.total); } } Choose the correct option. Consider the code given below. class Beverage { public void ingredients() { System.out.println("Basic ingredients"); } public void price() { System.out.println("Price not set"); } } class Coffee extends Beverage { public void ingredients() { System.out.println("Contains coffee beans and water"); } public void price() { System.out.println("Price: 100"); } } class Latte extends Coffee { public void ingredients() { System.out.println("Contains coffee beans, milk, and water"); } public void maker() { System.out.println("Makes latte"); } } public class BeverageTest { public static void main(String[] args) { Coffee drink = new Latte(); // LINE 1 drink.ingredients(); drink.price(); drink.maker(); // LINE 2 } } Choose the correct option. Consider the following Java code that uses chained exceptions. class FileProcessingException extends Exception { public FileProcessingException(String message) { super(message); } } class InvalidFileFormatException extends Exception { public InvalidFileFormatException(String message) { super(message); } } public class FileExceptionTest { public static void main(String[] args) { try { processFile(); } catch (FileProcessingException e) { System.out.println(e.getMessage()); System.out.println(e.getCause().getMessage()); } } public static void processFile() throws FileProcessingException { try { validateFile(); } catch (InvalidFileFormatException e) { FileProcessingException fpe = new FileProcessingException("Error processing file"); fpe.initCause(e); throw fpe; } } public static void validateFile() throws InvalidFileFormatException { throw new InvalidFileFormatException("File format not supported"); } } What is the output of this code?