Results 1 to 10 of 10
Thread: Class Interface or enum expected
- 12-19-2011, 03:45 AM #1
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
- 12-19-2011, 04:10 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Class Interface or enum expected
Could you please show your code. Just looking at what you have posted, quite difficult to comment.
- 12-19-2011, 07:53 AM #3
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
Re: Class Interface or enum expected
Hi Eranga,
Actually I have figured out the error now, I was by mistake using "Class" instead of "class" for defining the class interface.
But still I want to know all other possible causes of the error.
It would be very nice of you, if you put some light onto this
Thanks in advance
Best Regards,
Ankit
- 12-19-2011, 08:02 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Class Interface or enum expected
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-19-2011, 09:00 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Class Interface or enum expected
- 12-19-2011, 09:47 AM #6
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
Re: Class Interface or enum expected
Thanks a lot Jos :), I will work accordingly.
- 12-22-2011, 04:22 AM #7
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
Re: Class Interface or enum expected
Hi All,
If i have declared a function in my class that has void as it's return type then can i use it in System.out.println(""+ fun()) ??
Here is the sample code..
Here is the error:-Java Code:class Box { double width; double height; double depth; //Method declaration void vol() { System.out.println(width*height*depth) ; } } class BoxDemo { public static void main(String[] args) { Box mbox1 = new Box(); Box mbox2= new Box(); /* Assigning values to the instance variable*/ mbox1.width=10; mbox1.height=20; mbox1.depth=15; mbox2.width=3; mbox2.height=6; mbox2.depth=10; /* Calculating volumes*/ System.out.print("the volume of box1 is:=" + mbox1.vol()); System.out.print("the volume of box1 is:="); mbox2.vol(); } }
D:\JAVA\Practice>javac BoxDemo.java
BoxDemo.java:39: 'void' type not allowed here
System.out.print("the volume of box1 is:=" + mbox1.vol());
Please suggest.
Thanks
AnkitLast edited by pbrockway2; 12-22-2011 at 05:13 AM. Reason: code tags added
- 12-22-2011, 05:12 AM #8
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: Class Interface or enum expected
The compiler is saying "no": 'void' type not allowed here.If i have declared a function in my class that has void as it's return type then can i use it in System.out.println(""+ fun()) ??
Have vol() return width*height*depth instead of printing it. And change its name to getVol().
Or leave it as it is, but change the name to printVol() and say:
The first approach is preferable because returning the volume will be useful in lots of contexts not just printing it.Java Code:System.out.print("the volume of box1 is:="); mbox1.printVol();
- 12-22-2011, 08:23 AM #9
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
Re: Class Interface or enum expected
Hi pbrockway2,
Thanks a lot for the info.
I have made the changes suggested by you :), now the program is working fine and yes i have changed the name of the function to "getVol()".
Thanks
Ankit
- 12-22-2011, 09:10 AM #10
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Similar Threads
-
class interface or enum expected Imports java.io.*; error
By prathamkool in forum New To JavaReplies: 2Last Post: 10-02-2011, 04:53 PM -
keep getting error message class, interface, or enum expected
By darr in forum New To JavaReplies: 2Last Post: 10-02-2010, 02:13 AM -
class, interface or enum expected?
By Addez in forum New To JavaReplies: 2Last Post: 08-26-2009, 07:54 PM -
E:\IT 215 Java Programming\GUI1.java:125: class, interface, or enum expected
By tlouvierre in forum New To JavaReplies: 1Last Post: 05-31-2009, 10:57 PM -
illegal start of expression & class, interface, or enum expected
By silverq_82 in forum New To JavaReplies: 9Last Post: 08-08-2007, 07:16 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks