• 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

Assignment

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, the code below doesn't give any compilation / run time errors

-----------------------------------------------------------------
class A{}
class B extends A implements E{}//line 1
class C extends A{}
class D extends B{}
interface E{}
public class Question07 {
public static void main(String[] args) {
A a = new D();//line 2
C c = new C();//line 3
E e = (E)a;//line 4
B b = (B)e;//line 5
}
}

--------------------------------------------------------------------

question :

1) How to identify that "line 4" and " line 5" is valid is it is based upon the object created / the reference it is pointing to ???

2) I need to know how the instanceof operator works for the above code for each and every condition.


Pls. let me know about these two in detail...

Thanks in advance
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what you're asking. The instanceof operator works at runtime. It returns "true" if the type of the object on the left is the class named on the right, any subclass of that class, or, if the right-hand argument is an interface, if that object's class, or any superclass of that class, implements that interface. Is there something specific about these cases that you don't understand?

In any event, please post SCJP questions in the SCJP forum, not here. I'll move this to SCJP for you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic