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

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.
 
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic