What output does the following program display?
import java.util.EmptyStackException; import java.util.Stack; public class Main { public static void main(String args[]) { String s1 = "abc"; String s2 = "def"; Stack<String> stack = new Stack<>(); stack.push(s1);//www .j av a 2 s . c o m stack.push(s2); try { String s3 = stack.pop() + stack.pop(); System.out.println(s3); } catch (EmptyStackException ex) { } } }
abcdef
defabc
abcabc
defdef
B.
Stacks are last-in first out.