• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

1.4....K$B question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the foll is a question of chapter 3 Q 2..
1 import java.awt.*;
2 class T extends C{
3 PSVM(String[] args){
4 T t = new T();
5
6 }
7 }
//PS. T is ticker and C is Component..

What could be legally inserted in line 5...??

One of the wrong options are...

F......boolean test = (t instanceof String);

acc to the expn, " string is not in the heirarchy of t object"

My doubt, if this is so, i accept, but still it is legal. the implications of this is test=false. that is it. how come the option is wrong???
it is legal, but false...

please help o'veterans..
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because compiler can at compile-time tell, that t (Ticker) is not related to String.
Compiler knows that Ticker is not ancestor nor descendant of String, and consider parameters (of instanceof) as incompatible.

try to change t to Object variable


and now it is working. t is of type Object, so it is possible to have String object reference in type Object reference (upcasting).

when t is Ticker, it doesn't look like upcasting, doesn't look like downcasting, and you have compile-time error: incompatible types

> please help o'veterans
:-)
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello "java ojava"-

Welcome to JavaRanch.

On your way in you may have missed that we have a JavaRanch Naming Policy for displayed (screen) names. Your displayed name must consist of a first name (or an initial), a space, and a family name (in that order) and not be obviously fictitious. Since yours "java ojava", does not conform with it, please take a moment to change it, which you can do right here.

Posters with nonconforming displayed names will be locked out of JavaRanch after a few posts using those names.

Thanks
-Barry

(NR) - search tag
 
gagan bhatia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Orders followed SIR..
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by gagan bhatia:
Orders followed SIR..



Thankyou.
 
Legend has it that if you rub the right tiny ad, a genie comes out.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic