Results 1 to 7 of 7
Thread: Need help with Object Casting
- 10-17-2012, 07:03 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Need help with Object Casting
Hey, i'm currently learning Casting and i have been having some difficulties!
.gif)
I have 2 classes:
A superclass called Apple and a subclass called GreenApple:
GreenApple:
Apple:Java Code:public class GreenApple extends Apple { GreenApple a = new GreenApple(); Boolean greenColour; a = a2; a2 = (Apple) a; GreenApple() { greenColour = true; } }
and i get the following compilation errors:Java Code:public class Apple { public static void main(String[] args) { GreenApple appleColour = new GreenApple(); System.out.println(appleColour.greenColour); } }
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token ";", { expected after this token
Syntax error on token "{", ; expected
at GreenApple.<init>(GreenApple.java:3)
at Apple.main(Apple.java:4)
whats wrong?
- 10-17-2012, 08:48 PM #2
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
Re: Need help with Object Casting
....
Last edited by steveo314; 10-17-2012 at 08:55 PM.
- 10-17-2012, 08:53 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Need help with Object Casting
Still getting the same errors
- 10-17-2012, 09:01 PM #4
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
Re: Need help with Object Casting
I'm playing with your code right now too.
Yea its nothing with the semi-colon.
I'm gettin errors on lines 4 & 5 of the GreenApple class about identifiers....
- 10-17-2012, 09:03 PM #5
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
Re: Need help with Object Casting
What are you wanting a and a2 to do?
- 10-17-2012, 09:53 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Re: Need help with Object Casting
Remove lines #2, #4 and #5 from your GreenApple class; at least it will compile then. Never try to run anything when if didn't compile.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-17-2012, 10:05 PM #7
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Casting a String object to a Form object
By kakinyim in forum CLDC and MIDPReplies: 0Last Post: 04-23-2011, 11:41 AM -
Object Casting, please help
By DerekRaimann in forum New To JavaReplies: 5Last Post: 12-04-2010, 01:14 PM -
Casting Object to another type
By green_river48 in forum New To JavaReplies: 12Last Post: 04-03-2010, 10:52 AM -
Object casting
By spiderweb in forum Advanced JavaReplies: 5Last Post: 08-20-2009, 05:43 PM -
Object to Int casting
By nn12 in forum New To JavaReplies: 4Last Post: 12-06-2008, 10:58 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks