wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner classes" Watch "Inner classes" New topic
Author

Inner classes

sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
public class Selftest10 {
public static void main(String[] args)

{
class Horse {
public String name;
public Horse(String s)

{
name = s;
}
}
Object obj = new Horse

("Zippo");
Horse h = (Horse) obj;
System.out.println(h.name);
}
}
Can you explain why iam getting an error of casting here
anil kumar
Ranch Hand

Joined: Feb 23, 2007
Posts: 447
hi
sravanthi
i have executed your program i am not getting any error
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
Its showing incomaptible types
why is that so??
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Pulukuri,

Code just compiles fine and gives the desired result.
If you think, error must come, ask yourself why?

From my part, everything is fine there.



Thanks and Regards.


cmbhatt
anil kumar
Ranch Hand

Joined: Feb 23, 2007
Posts: 447
hi
i have changed the class name as self
i got this output

C:\practice>javac Self.java

C:\practice>java Self
Zippo

check it once
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Pulukuri,


Post the error generated by the compiler, including the line number!
Do you have a class named "Object" (in the current directory) or somewhere coming in the classpath. It can be one and only reason as I guess, you program is not getting compiled well.

Thanks and Regards,
cmbhatt
[ April 02, 2007: Message edited by: Chandra Bhatt ]
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi Chandra,

You got it Correct. She maight have Object class of her own. thats why casting fails.

Good yaar.


Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
Hi
What chandra said is absolutely correct, i had other class file with same name,now its working fine
Thanks so much
 
 
subject: Inner classes
 
Similar Threads
my Overload program
Inner Class
method-local inner class
Chapter 8 - Question 5 - Page 695
Java noob needs help