Results 1 to 6 of 6
Thread: Method Casting help...
- 03-07-2012, 12:26 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 31
- Rep Power
- 0
Method Casting help...
I am trying to write a code that calls the method from the last class in itself to print out the letter A. This can only be done through casting, but unfortunately I am having trouble grasping the concept. I have read up on it on the internet but apparently I still don't understand the concept. Here is what I have
It says I need to create a class doIt but I don't think I need to do that. I think there is another solution. Also it is not picking up my test method from the A class. Any help would be greatly appreciated!Java Code:public static void main(String[] args) { new Worker.doIt(); } class Worker { void doIt() { base myVar=new A(); (()myVar)test(); } } class base { } class A extends base { public void test() { System.out.println("A"); } } }Last edited by Norm; 03-07-2012 at 01:28 AM. Reason: corrected code tags
- 03-07-2012, 01:30 AM #2
Re: Method Casting help...
You have posted bits and pieces of your program. No way to tell what the code does or what you intend for it to do.
Post code that will compile and execute.
If you get compiler errors, post them.
If you get execution errors, post them.
If it executes, show the output and explain what is wrong with it and show what it should be.
- 03-07-2012, 01:34 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 31
- Rep Power
- 0
Re: Method Casting help...
the goal is to cast the method in the A class to the original and have it print out A as stated in the OP. The compiler displays
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Worker.doIt cannot be resolved to a type
at cw0306a.main(cw0306a.java:6)
- 03-07-2012, 01:37 AM #4
Re: Method Casting help...
What do you mean by "cast the method"?the goal is to cast the method
Do you mean to cast the value that is returned by a method?
This error from your IDE doesn't say what the error is.Unresolved compilation problem:
Can you compile the code with the javac compiler and get an error message?
- 03-07-2012, 02:16 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Method Casting help...
In Java you cast variables and other expressions, you don't cast methods. Perhaps it would help if you posted the actual question. Don't worry: nobody will spoonfeed you a solution. But it may shed some light on what you are being asked to do.
- 03-07-2012, 09:59 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Method Casting help...
Please do not ask for code as refusal often offends.
Similar Threads
-
casting an int
By droidus in forum New To JavaReplies: 1Last Post: 09-07-2011, 06:38 PM -
Casting int[][] to int[]
By subith86 in forum New To JavaReplies: 2Last Post: 02-02-2011, 10:48 AM -
Casting
By zzpprk in forum Advanced JavaReplies: 13Last Post: 08-13-2009, 07:59 PM -
What does casting mean?
By sev51 in forum New To JavaReplies: 3Last Post: 01-27-2009, 04:31 PM -
casting help
By soc86 in forum New To JavaReplies: 4Last Post: 01-13-2009, 11:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks