• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Anyone explain these answer

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 )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
The code does not compile.
The code compiles cleanly and shows "StringBuffer Version".
The code compiles cleanly and shows "String Version"
The code throws an Exception at Runtime.
ans 1
2) An Interface can never be private or protected.
Answers
True
False
ans false
3)
public XXXX extends something1, something2

XXX should be an interface,something1 and something2 need not, for the expression to be legal
XXX should be a class, something1 and something2 must be interfaces for the expression to be legal.
XXX, something1 and something2 must be interfaces for the expression to be legal.
The above statement is alway illegal in Java as multiple inheritance is not supported.
ans 3
4)
Read this piece of code carefully
if("String".replace('T','t') == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
Answers
the code will compile an print "Equal".
the code will compile an print "Not Equal".
the code will cause a compiler error
ans 1
5) Read this piece of code carefully
if("String".replace('g','G') == "String".replace('g','G'))
System.out.println("Equal");
else
System.out.println("Not Equal");
Answers
the code will compile an print "Equal".
the code will compile an print "Not Equal".
the code will cause a compiler error
ans 2
6) public class ADirtyOne
{
public static void main(String args[])
{
System.out.println(Math.abs(Integer.MIN_VALUE));
}
}
an attempt to compile and run the above class will
Cause a compiler error.
Cause no error and the value printed on the screen is less than zero.
Cause no error and the value printed on the screen is one more than Integer.MAX_VALUE
Will throw a runtime exception due to overflow - Integer.MAX_VALUE is less in magnitue than Integer.MIN_VALUE.
ans 2
7)
what does the following expression return?
(0.0 == -0.0)

true
false
ans 1
8)
What does the following expression print on the screen?
System.out.println(Math.min(Float.NaN, Float.POSITIVE_INFINITY));

NaN
Infinity
The expression throws a runtime exception - NaN is an illegal argument.
ans 1
8 )Assume that th is an instance holding a thread object. th.start() causes the thread to start running and eventually complete its execution. The object reference by th is not accessable any more and is garbage collected when the garbage collecter runs.

True
False
ans 2
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even before anyone start answering your questions, could you please post one question per thread? There is no restriction on how many questions one person can post, but restrict one question per post so that it is easier for others to grab what they are interested in!
Ajith
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
1) two things, null is java keyword, and second method is expecting a object reference not object value.(i am not sure abt my ans).
2)An interface is basically a pure abstract clas, and any class can't by private/protected.
3) Ans should be 4, multiple interface is not allowed in Java.
4) and 5), here comes associativity, in 4), String.replace returns String which is == to "String and in 5), left hand operation occurs with result "StrinG" which is compared to "String" before replace method call.
6)"Note that if the argument is equal to the value of integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative." from JDK documentation. Why it happens, I also would like to know!!!
7)Hmmmm.... in mathematics 0.0 == -0.0 ... this hold good in Java also
8)Float.Nan != Float.NaN In these operations, Java returns result Nan always. It can't used in any type of calculations.
9)When thread is stopped, it is dead, but that object still holds good. Instances still can call it's methods after it has finished running. So therefore there is no Question of Garbage collection.
Hope it helps
Ashish
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bala,
I have seen so many of ur posts. One kind advice. Pls. dont expect spoon feeding. You just come across some mock tests and put that here expecting someone will give u replies. For example 0.0 = -0.0 is true and min(-0.0,0.0) is -0.0 Its a basic concept where u can read from JLS. Same applies to almost all the Qs u have asked for. Moreover check www.javaranch.com/Maha site. She has put all the old discussions topicwise very nicely. Check that. Before putting a post try refering that in books, notes or in old discussions. Please dont take it as offense. Just a suggestion. Thanks.
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic