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...");
}
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...");
}
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.
ReplyDeleteIt 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.
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.
ReplyDeletebest rpa training in bangalore
rpa training in bangalore
rpa course in bangalore
RPA training in bangalore
rpa training in chennai
rpa online training
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.
ReplyDeletebest rpa training in bangalore
rpa training in bangalore
rpa course in bangalore
RPA training in bangalore
rpa training in chennai
rpa online training
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.
ReplyDeletepython training in chennai
python course institute in chennai
ReplyDeleteWhoa! 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
Thank you for bestowing the great article. It delivered me to understand several things about this concept. Keep posting such surpassing articles so that I gain from your great post.
ReplyDeleteJMeter Training in Chennai
JMeter Training Institute in Chennai
Power BI Training in Chennai
Job Openings in Chennai
Pega Training in Chennai
Linux Training in Chennai
Corporate Training in Chennai
Tableau Training in Chennai
Oracle Training in Chennai
JMeter Training in Adyar
JMeter Training in Anna Nagar
very informative blog and useful article thank you for sharing with us , keep posting learn more about aws with cloud computing
ReplyDeleteAWS Online Training
Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this.
ReplyDeleteamazon web services training institutes in bangalore
amazon web services training in bangalore
best amazon web services training institutes in bangalore
amazon web services training course content
amazon web services training interview questions
amazon web services training & placement in bangalore
amazon web services training center in bangalore
This information you provided in the blog that is really unique I love it!!
ReplyDeleteAWS Training in delhi
Colossal Articles and contents are posted Here...Great Share about AWS Training!!!keep it up
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
Great information, Thanks for sharing the such a great information.
ReplyDeleteJava Online Training
Java Online Training In Chennai
Java online Course in Chennai
Such a good post .thanks for sharing
ReplyDeleteSalesforce Training in T Nagar
Salesforce Training in Chennai
Great post. keep sharing such a worthy information.
ReplyDeleteSEO Training in Chennai
SEO Course
kralbet
ReplyDeletebetpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
betmatik
FLD
fghnfgnmghmghm
ReplyDeleteشركة صيانة افران بمكة
شركة كشف تسربات المياه بالقطيف 29xWe7PdSu
ReplyDeleteشركة صيانة افران بالاحساء vSro0CXtkd
ReplyDeleteشركة تنظيف منازل بخميس مشيط KHxoTZk7Vu
ReplyDelete