What will be the output of the following code snippet? class…
What will be the output of the following code snippet? class Animal { void makeSound() { System.out.println(“Animal sound”); } void sleep() { System.out.println(“Animal sleeps”); } } class Dog extends Animal { @Override void makeSound() { System.out.println(“Bark”); } void fetch() { System.out.println(“Dog fetches”); } } public class Main { public static void main(String[] args) { Animal a = new Dog(); a.makeSound(); a.sleep(); } }
Read DetailsWhat does this transaction block do if the second insert fai…
What does this transaction block do if the second insert fails? Connection con = DriverManager.getConnection(url, user, pass); con.setAutoCommit(false); try { Statement stmt = con.createStatement(); stmt.executeUpdate(“INSERT INTO users(name) VALUES (‘John’)”); stmt.executeUpdate(“INSERT INTO users(email) VALUES (‘test@example.com’)”); // Fails con.commit(); } catch (SQLException e) { con.rollback(); System.out.println(“Rolled back”); }
Read DetailsWhat will be the output order of the messages below? Threads…
What will be the output order of the messages below? Threads call print(“A”), print(“B”), print(“C”) on the same instance. class Printer { void print(String msg) { synchronized(this) { System.out.println(“[” + msg + “]”); try { Thread.sleep(100); } catch (InterruptedException e) {} } } }
Read Details