top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Compiled and run this code and give the output of the snippet.

+2 votes
467 views
public class test {
    public static void main(String args[]) { 
    String s1 = "abc";
    String s2 = "abc";
    if(s1 == s2)
        System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }
}
posted Jan 12, 2016 by Divya Shree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Compilation Error because class test is public, should be declared in a file named test.java but if class name is without 'public' declaration then ans is 1 and 3.

answer Feb 12, 2016 by Shivam Kumar Pandey
0 votes

1 3

answer Jan 12, 2016 by Kavana Gowda
Similar Questions
+1 vote
public class example 
{
     int i[] = {0};
         public static void main(String args[])
    {
         int i[] = {1};
          change_i(i);
          System.out.println(i[0]);
      }
      public static void change_i(int i[]) 
       {
         i[0] = 2;
         i[0] *= 2;
      }
}
+1 vote
class test
 {
    static boolean check;
    public static void main(String args[])
   {
        int i;
        if(check == true)
            i=1;
        else
            i=2;
        if(i=2) i=i+2;
        else i = i + 4;
        System.out.println(i);
     }
}
+2 votes

I declared a variable and incremented/modified it inside Mapper class. Now I need to use the modified value of that variable in Driver class. I declared a static variable inside Mapper class and its modified value works in Driver class when I run the code in Eclipse IDE. But after creating that code as a runable jar from Eclipse and run jar file as “$ hadoop jar filename.jar input output” modified value does not reflect (value is 0) in Driver class.

...