Java Interview Questions

Swith Statement

1. What is the output of the class

public class SwithClass {

public static void main(String a[]){

int price = 6;
switch (price) {

case 1: System.out.println("case 1");
case 3: System.out.println("case 3");
default: System.out.println("It is: default");
case 9: System.out.println("case 9");

}
}
}



2. output?

public class StringEquals {

public static void main(String[] args) {

String str = "abc";
String str1="abc";
System.out.println(str.equals(null) | str1.equals("abc"));
System.out.println(str.equals(null) || str1.equals("abc"));


}

}




3. Which method it calls?

public static void main(String[] args) {
method(null);
}
public static void method(Object o) {
System.out.println("Object impl");
}
public static void method(String s) {
System.out.println("String impl");
}



4. What is the output if flag is true or flag is false

boolean flag= false;

try {
if (flag) {
while (true) {

}
} else {
System.exit(0);
}
} finally {
System.out.println("In Finally");
}



5. Predict what is the output

String s1 = "abc";
String s2 = "abc";

String abc = new String("Abc");

boolean s3 = s1 == s2;

System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
System.out.println(s1.equals(abc));
System.out.println(s1.hashCode());
System.out.println(s2.hashCode());
System.out.println(abc.hashCode());


6. What is the output of the Program

try{
int data=25/0;
System.out.println(data);
}
catch(NullPointerException e){
System.out.println(e);
}
finally{
System.out.println("finally block is always executed");
}
System.out.println("rest of the code...");


7. And also this

public static void main(String args[]){
try{
int data=25/0;
System.out.println(data);
}

catch(ArithmeticException e){System.out.println(e);}

finally{System.out.println("finally block is always executed");}

System.out.println("rest of the code...");
}



Comments

  1. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog.
    It is very nicely explained. Your article adds best knowledge to our Java Online Training from India.
    or learn thru Java Online Training from India Students.

    ReplyDelete
  2. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    best rpa training in bangalore
    rpa training in bangalore
    rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  3. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    best rpa training in bangalore
    rpa training in bangalore
    rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  4. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    python training in chennai
    python course institute in chennai

    ReplyDelete


  5. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    AWS Training in Bangalore | Best AWS Amazon Web Services…
    Amazon Web Services Training in Pune India
    AWS Online Training in India | AWS Training | AWS online training
    AWS Training in Bangalore | Aws training in Bangalore with placements

    ReplyDelete
  6. very informative blog and useful article thank you for sharing with us , keep posting learn more about aws with cloud computing

    AWS Online Training

    ReplyDelete
  7. This information you provided in the blog that is really unique I love it!!
    AWS Training in delhi

    ReplyDelete
  8. Great post. keep sharing such a worthy information.
    SEO Training in Chennai
    SEO Course

    ReplyDelete

Post a Comment

Popular posts from this blog

Theme display in javascript

How to know which liferay version we are using

Viewing the SQL Query in liferay : debugging the SQL Query in Hibernate