13:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.130 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 13:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.1313:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.13

.

.

Thursday, May 26, 2011

Random Java Questions & Answers from Angelfire.com

 Read this piece of code carefully
if("String".toString() == "String")
    System.out.println("Equal");
else
    System.out.println("Not Equal");

Answers
 
1.     the code will compile an print "Equal".

Read the code below. Will be the result of attempting to compile and run the code below.
 
public class AQuestion
{
     public void method(Object o)
     {
         System.out.println("Object Verion");
     }
 public void method(String s)
 {
    System.out.println("String Version");
 }
 public static void main(String args[])
 {
     AQuestion question = new AQuestion();
     question.method(null);
 }
}
Read the code below. Will be the result of attempting to compile and run the code below.
 
public class AQuestion
{
     public void method(StringBuffer sb)
     {
         System.out.println("StringBuffer Verion");
     }
 public void method(String s)
 {
    System.out.println("String Version");
 }
 public static void main(String args[])
 {
     AQuestion question = new AQuestion();
     question.method(null);
 }
}
Answers
  1. The code does not compile.


Question 5.
    Read the following code below.
public interface AQuestion
{
     public abstract void someMethod() throws Exception;
}
A Class implementing this interface should 


1.     Should have the method public void someMethod() which need not throw an Exception.

Question 6.
        An Interface can never be private or protected.
False


Question 7.
      A Vector class in jdk 1.2
1.     is public
2.     is final
3.     implements java.util.List
4.     is serializable
5.     has only One constructor
Answers: 1, 3, 4


  A String Class
1.     is final
2.     is public
3.     is serializable
4.     has a constructor which takes a StingBuffer Object as an Argument
Answer: 1, 2, 3, 4


Question 9.
 
public interface AQuestion
{
     void someMethod();
}
The class which implements AQuestion
1.     Should have someMethod which must necessarily be public.
2.     Should have someMethod which could be "friendly" or public
3.     Should have someMethod which should not throw any checked exceptions.
4.     Should have someMethod which cannot be sychronized as sychronized is not in the signature of the interface defination
Answer: 1, 3


Question 10.
 
public class AQuestion
{
 private int i = j;
 private int j = 10;
 public static void main(String args[])
 {
      System.out.println((new AQuestion()).i);
 }
}

Answers
1.     Compiler error complaining about access restriction of private variables of AQuestion.
2.     Compiler error complaining about forward referencing.
3.     No error - The output is 0;
4.     No error - The output is 10;

Answer: 2


The code compiles cleanly and shows "String Version