Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Paul Clapham
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Saloon Keepers:
Tim Holloway
Carey Brown
Roland Mueller
Piet Souris
Bartenders:
Forum:
Programmer Certification (OCPJP)
The type Box is already defined
Srinivas Palam
Ranch Hand
Posts: 73
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Type: 1
package Test; class Box { int width; int depth; int height; Box (int w, int d, int h){ width = w; depth = d; height = h; } double volume() { return width * depth * height; } } public class BoxDemo { public static void main(String args[]) { Box b1 = new Box(1,2,1); Box b2 = new Box(2,3,2); double vol; vol = b1.volume(); System.out.println("Volume is " + vol); vol = b2.volume(); System.out.println("Volume is " + vol); } }
Type 2:
package Test; class Box { ------------------> // Line 1 error: The type Box is already defined double width; double height; double depth; Box(double w, double h, double d){ width = w; height = h; depth = d; } Box (Box ob) { width = ob.width; height = ob.height; depth = ob.depth; } Box() { width = -1; height = -1; depth = -1; } Box(double len){ width = height = depth = len; } double volume() { return width * height * depth; } } public class BoxPassOb { public static void main(String args[]) { Box ob1 = new Box(1,1,1); Box ob2 = new Box(); Box ob3 = new Box(2); Box myclone = new Box(ob1); double vol; vol = ob1.volume(); System.out.println("Ob1 --> " + vol); vol = ob2.volume(); System.out.println("Ob2 --> " + vol); vol = ob3.volume(); System.out.println("Ob3 --> " + vol); vol = myclone.volume(); System.out.println("myclone --> " + vol); } }
Why am I getting
The type Box is already defined
error in Type2 class description.
Togaf Part 1 and 2
Girish Bal
Ranch Hand
Posts: 79
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Did you create both classes in Type 1 and Type 2 in same package?
Girish B
SCJA 1.0 (86%)
SCJP 1.4 (91%)
OCPJWCD (86%)
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Inheritance, and the mis-use of the 'static' keyword
End of file while parsing
cannot find symbol - constructor error while extending a class
(Inheritance) please Help!
static reference to nonstatic var & methods
More...