• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binding  RSS feed

 
Pranshul Bajaj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Which of the  lines above would give the output Right On top!   ?
Can anyone explain with the reasons the concept behind it?
 
Stephan van Hulst
Saloon Keeper
Posts: 7974
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try to compile and run this code? That way you can figure out for yourself which statements are valid.
 
Pranshul Bajaj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay,next time i ll do that.I wasn't known this time.
I know which lines will produce an output but i want to understand the concept behind it.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which lines do you think are correct?
 
Pranshul Bajaj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3rd,4th and 6th line.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 1 is missing a dot operator. Work out whether it will compile or not if you replace the space with a dot.
Lines 2 and 5 both suffer the same problem (see below).
I think 3 4 6 is correct.

What you are doing in line 2 is casting. But the cast has a lower precedence than the dot operator, so what is happening is that you are casting the output of the tellItLikeItIs method. Which can't be cast. Isn't that method void, too. If you want to cast the reference, you need a second pair of ().
 
Pranshul Bajaj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay,if the 1st line is written like this:-
speakIt.tellItLikeThis();     //1
it isn't compiling like this and what's the reason for it?
speakIt is a reference variable pointing to the object of Tell class object. isn't it?
   
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
speakIt does not have a method by that name, nor an abstract method, therefore it can't behave in a polymorphic way.
 
Pranshul Bajaj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
0kay,got it!! Thankyou very much
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!