• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Queries

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have listed queries which I came across while solving mock exams.Please let me know.


What is the correct answer and why?

What is valid and why?

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Smitha,
Well the questions you've listed are fairly simple to understand and reason. I wish we get such questions in the real exam too.

Well here are the answers:

Answer to your first question:

The code fails to compile. The compiler complains that the assignment "s1 = (Subclass1)s2" is illegal.



This is simply because Subclass1 and Subclass2 are peer classes. Peer classes do not have knowledge about each other. So if you try to cast from one peer class to the other, the compiler will complain. I hope you know what are peer classes :

B a s e
/ \
Subclass1 Subclass2
Subclass1 and Subclass2 are peers so an object of Subclass1 will not have any idea of an object of Subclass2.

Answer to your second question:
1.public transient static final int _FRAMEX = 850; //Is absolutely fine
2.this("a", "b"); // Is absolutely fine
3.private transient static final int _FRAMEX = 850; //Is absolutely fine
4.boolean b = 0; // Is ERRONEOUS
5.short s=128; //Is absolutely fine
6.int x=(int)(1.23); //Is absolutely fine.

Why ? Because a boolean variable can have only values true or false. 0 is an integer so it cannot be assigned to boolean.

Answer to your next question:
If null is passed , Is string version executed ?

Yes.

And the answer to your last question
Why code does not compile ?

Because bo the methods method(StringBuffer sb) and method(String s) take objects of String type so the compiler complains that methods are ambiguous.

Hope this helps
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The answer to the last two questions lies in the fact that the most specific method is chosen.
For information on the most specific method, here is the link...
corey's tipline
thanks,
vinu.
 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

the answer for the first question can also b last one ...why coz a parent class cannot have two child classes.......
right ........

one more doubt ...how come null is taken to string type....


thanks & regards

srikanth reddy..
 
Smitha Ballikar
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

I went through all the explanations.Thanks for all of them!!
But I am slightly still not clear why string version is excuted when null is passed as a argument.And the same thing doesnt happen in second version of code when null is passed though it also has a string verion
reply
    Bookmark Topic Watch Topic
  • New Topic