java, c search engine

Advance java, c++,sql search engine

10/31/09

Java objective questions and answer with solution

(1)
public class This {
    public static void main(String[] args) {
         int a=5,b=10,c=8;
         long s=a>b?c:a>c?b=+b++:++b;
         System.out.print(s);
    }
}
What will output when you compile and run the above code?
(a)11
(b)21
(c)20
(d)Compiler error
Answer: (a)
(2)
public class BreakDemo {
    public static void main(String[] args){
         String[][]alpha={{"a"},{"b","c"}};
         for(String str[]:alpha)
         {
             for(String s:str)
             {
                 System.out.print(s+" ");
                 if(s.equals("b")) return;
                
             }
         }
    }
}
What will be output of above program?
(a)a null
(b)a null b
(c)a b
(d)Compiler error
Answer:(c)
(3)What will be output of following program?
public class Datatype {
    public static void main(String[] args) {
         byte b=125;
         b=(byte)(b*2);
         System.out.println(b);
            
    }
}
(a)15
(b)12
(c)9
(d)6
Answer: ()
(4) Which of the following is not primitive data type?
(a) int
(b) char
(c) String
(d) double
Answer: (c)
Explanation:
String is not a keyword of java. It is class of java which has been defined in java.lang.String
(5)
class Operator
{
    public static void main(String[] args)
    {
         int a=5;
         int c=0;
         c=+-a+++a;
         System.out.println(c);
    }
}
What will output when you compile and run the above code?
(a)0
(b)1
(c)-11
(d)Compiler error
Answer: (b)

Java placement questions and answer with solution

(1)
public class This {
    public static void main(String[] args) {
         int a=5,b=10,c=8;
         double s=true?5F:"string";
         System.out.print(s);
    }
}
What will output when you will compile and run the above code?
(a)5
(b)null
(c)Run time exception
(d)Compiler error
Answer: (d)
(2)
public class BreakDemo {
    public static void main(String[] args){
         int a=2;
             if(a==2)
                 break first;
             System.out.print("step1");
             first:
             System.out.println("step2");
    }
}
What will be output of above program?
(a)step1
(b)step2
(c)step2
   Step1
(d)Compiler error
Answer:(d)
(3)What will be output of following program?
public class Datatype {
    public static void main(String[] args) {
         short b=1000;
         b=b*5;
         System.out.println(b);
            
    }
}
What will output when you compile and run the above code?
(a)5000
(b)5000h
(c)5000H
(d) Compiler error
Answer: (d)
Explanation:
(4)
class BitwiseOperator
{
    public static void main(String[] args)
    {
         byte a=-10;
         int b=(a>>>2)%(a<<<2);
         System.out.println(b);
    }
}
What will output when you compile and run the above code?
(a)0
(b)-1
(c)-3
(d)Compiler error
Answer: (d)
(5)
class Operator
{
    public static void main(String[] args)
    {
         int a;
         a=(new Operator()).calulate();
         System.out.println(a);
    }
    int calulate()
    {
         int p=0,q=2;
         p=q+~p+ ++3;
         int r= true ? return p: return 10;
    }
}
What will output when you compile and run the above code?
(a)10
(b)5
(c)-3
(d)Compiler error
Answer: (d)

Java interview questions and answer with solution

(1)
public class This {
    public static void main(String[] args) {
         int a=5,b=10,c=8;
         double s=true?5D:void;
         System.out.print(s);
    }
}
What will output when you compile and run the above code?
(a)5
(b)0
(c)NaN
(d)Compiler error
Answer: (d)
(2)
public class BreakDemo {
    public static void main(String[] args){
         int a=2;
         india: {
             ++a;
             if(a==3)
                 break india;
         }
             System.out.print(a);
            
    }
}
What will be output of above program?
(a)3
(b)4
(c)2
(d)Compiler error
Answer: (a)
(3)
public class Datatype {
    public static void main(String[] args) {
         long a=10;
         long b=20;
         long c=a-~b-1;
         System.out.println(c);
            
    }
}
What will output when you compile and run the above code?
(a)-10
(b)-11
(c) 30
(d) Compiler error
Answer :  (c)
Explanation:
(4)
public class EnumTest {
    public static void main(String[] args) {
         short a=5,b=10,c=11;
         int d=a&b^c|10;
         System.out.print(d);
    }
}
What will output when you compile and run the above code?
(a)0
(b)1
(c)11
(d)Compiler error
Answer: (c)
(5)
class Operator
{
    public static void main(String[] args)
    {
         int a=1,b=1,c=0;
         c=++a + b++;
         System.out.println(a+","+b+","+c);
    }
   
}
What will output when you compile and run the above code?
(a)2,2,3
(b)2,1,3
(c)2,4,2
(d)Compiler error
Answer: (a)