• 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

Inner Classes (2)

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class AB{
//1
public static void main(String ar[]){
//2
class A{
//3
public String name;
//4
public A(String s){
//5
name = s;
//6
}
//7
}
//8
Object obj = new A("XYZ"); whats happening here
//9
A h =(A) obj; here
//10
System.out.println(h.name);
//11
}
//12
}
//13

whats happening at line 9 and line 10
[ October 13, 2007: Message edited by: Burkhard Hassel ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hasitha Randika:
...whats happening at line 9 and line 10


In line 9, a new instance of A is created, and a reference to this instance is assigned to the variable "obj" which has a type of Object. This is an "assignment conversion," in which the reference type is implicitly upcast from type A to type Object.

In line 10, the reference held by "obj" is explicitly downcast from type Object to type A (the true runtime type of the instance), and assigned to the variable "h" which has a type of A.
[ October 13, 2007: Message edited by: marc weber ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic