The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Class  declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Class  declaration" Watch "Class  declaration" New topic
Author

Class declaration

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

which declartation are allow in the //
//
public class Orange{}
i know package qwt.two ,import java.awt.* can put on the //
i'm not sure class Apple() can put on the // or not?

package qwt.two
import java.awt.*
class Apple() {}
public class Orange{
//do something
}
is it correct for the above code?
please explain.
Micheal Zhao
Greenhorn

Joined: Aug 28, 2000
Posts: 4
I think so .
just try to compile and see the result.
Originally posted by Joe S:

which declartation are allow in the //
//
public class Orange{}
i know package qwt.two ,import java.awt.* can put on the //
i'm not sure class Apple() can put on the // or not?

package qwt.two
import java.awt.*
class Apple() {}
public class Orange{
//do something
}
is it correct for the above code?
please explain.

deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi,
Yes It's okay to have Apple class at //.
because there is no restriction on the no. of classes that u can write in a file except that only one of them can be public.
In this case Orange class is public but Apple is not.so Apple
reside along with Orange. had Apple also been public then this would have given a compilation error.
regards
deekasha
 
 
subject: Class declaration
 
Threads others viewed
Why this exception ?
Doubt in Exceptions.....
Constructor of parent abstrat class not getting executed.
casting
Package access problem.
developer file tools