Results 1 to 3 of 3
Thread: Does a method location matters?
- 12-28-2011, 04:35 AM #1
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
Does a method location matters?
Hi Mentors,
I was going through parametrized constructors, and i am facing an issue with the location of the method definition.
Please have a look at the code as below:-
Java Code:class Box { double width; double height; double depth; // Defining the parametrized constructors Box(double w, double h, double d) { if(w > 0) { width = w; } else { width = 1.0; } if(h > 0) { height=h; } else { height = 1.0; } if(d > 0) { depth = d; } else depth = 1.0; //Calculates and return the volume to the calling routines double getVol() { return depth*height*width; } } } class BoxDemo7 { public static void main(String[] args) { Box mbox1 = new Box(3,4,5); Box mbox2 = new Box(2,3,4); System.out.println("Volume for 1st Box is:=" + mbox1.getVol()); System.out.println("Volume for 2nd Box is:=" + mbox2.getVol()); } }
The error the javac compiler giving me is as below:-

But when i change the location of the getVol() function i.e above my parametrized constructor the code works fine for me.
Please suggest the needful.
Thanks in advance
Ankit GuptaLast edited by ankiit; 12-28-2011 at 04:52 AM.
- 12-28-2011, 06:26 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: Does a method location matters?
Double check the bracket locations in your code....as posted, the getVol method is within the Box constructor
- 12-28-2011, 06:59 AM #3
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
Similar Threads
-
hiding passed parameters using window.location.href = 'params' method
By kulangotski in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 07-01-2011, 12:49 PM -
JList Location
By BeeGee in forum Advanced JavaReplies: 8Last Post: 04-07-2010, 03:09 PM -
need to copy file from one location to another location
By naveen.dpt2007 in forum New To JavaReplies: 4Last Post: 02-28-2010, 03:53 PM -
location of click
By saima in forum AWT / SwingReplies: 3Last Post: 11-22-2009, 12:06 PM -
location provider returns no location
By sandeeprao.techno in forum CLDC and MIDPReplies: 0Last Post: 09-24-2009, 09:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks