Wednesday, January 16, 2013

1/16/2013 Java Certification


1. What is wrong with the following code?
abstract class TestClass{
   transient int j;
   synchronized int k;  //Variables cannot be declared synchronized. 
   final void TestClass(){}//This is not a constructor because it has return type
   static void f(){  //cannot be declared static Because it refers to instance variables j and k
      k = j++;
   }
}


2. You cannot store primitives in an ArrayList because only Objects can be stored in it.
An ArrayList is backed by an array.

Integer can be stored in it while int cannot.

3. There is no graph in Collections.


4. Trie Structure?



5. Overriding

class A{
   A() {  print();   }
   void print() { System.out.println("A"); }
}
class B extends A{
   int i =   Math.round(3.5f);
   public static void main(String[] args){
      A a = new B();
      a.print();
   }
   void print() { System.out.println(i); }
}






No comments:

Post a Comment