Showing posts with label java puzzles. Show all posts
Showing posts with label java puzzles. Show all posts

Saturday, February 20, 2010

Java Puzzles


1. Is it possible to cast like this ?
List strings = new ArrayList();
List objects = strings;

2. Will this work ?
List strings = new ArrayList();
Collection objects = strings;

3. Can we do it ?
Collection collection = new ArrayList();
collection.add("newString");

4. will this work ?
List objects = new ArrayList();
String s = (String) objects.get(0);