• 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

Problem With Class Hierarchy

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

I am having some hard time to understand the logic behavior of the below program.
The output for this

: Compile and Execute without any errors.



interface Min{}
class A{}
class B extends A implements Min{}
class C extends B{}

public class CCExp{
public static void main(String args[]){
A a=new A();
B b=new B();
C c=new C();
Min m=null;
b=(C)m;
m=(Min)b;
A a2=(A)m;
B b2=(B)a2;
Min m2=(C)b2;
C c2=(C)m2;
}
}


Could anybody please explain the logic of the above output in really easy to understand way?

Thanks.
-DJ

 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Use Code Tags when you post a source code. You can edit your message using button and then add code tags to it.

This question has been asked before many times. Searching for "examlab casting" will give you these discussions

https://coderanch.com/t/469221/Programmer-Certification-SCJP/certification/casting-from-examlab
https://coderanch.com/t/451028/Programmer-Certification-SCJP/certification/examlab-reference-variable-casting
 
Dj Lalotra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright..Point taken.

Thanks.
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic