Page 1 of 1

About Question enthuware.ocajp.i.v7.2.933 :

Posted: Thu Dec 20, 2012 7:06 am
by ETS User
"public class MyClass{ }
There can be only 1 "public" class within package scope in a file. You can have additional inner classes that are public though."
Why? I wrote this code
"package myPackedjedsccsdcscsdscd;
public class Test1{}
public class Test{
public static void main(String[] args){
System.out.println("Iworking!!!");
}
}
"
in Eclipse and he work.

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Thu Dec 20, 2012 8:35 am
by admin
You should not worry about what Eclipse or any IDE does. As per the specification there can be at most one public class in a file. So that is what you should remember for the exam.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Sun Dec 23, 2012 5:26 pm
by Svetopolk
ETS User wrote: in Eclipse and he work.
try to create an instance of Test1 and you will get an exception ....

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Wed Mar 20, 2013 11:07 am
by muttley
I think that you should specify in the question that the file is only one.
If the file were different the option £public class MyClass{ }" would correct also.

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Thu Aug 11, 2016 11:48 am
by namdevpatil93
how it is valid p.util package statement

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Thu Aug 11, 2016 12:37 pm
by admin
Not sure what you are asking. Could you please explain?

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Thu Mar 02, 2017 9:01 am
by AndaRO
So in a file we can have interfaces, abstract classes and one public class.
or can we have public abstract class and inner class non public.

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Thu Mar 02, 2017 10:50 am
by admin
You can have at most one public "thing" in a file at package score. It can be a class, an interface, or an enum. You can have multiple public inner classes.

You can also try it out to confirm.

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Sat Dec 01, 2018 8:55 pm
by ash4413
Hi there,
how it is valid p.util package statement of option 2?
Can anyone explain it?
thanks in advance

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Sat Dec 01, 2018 10:43 pm
by admin
Well, a class can belong to any package. So, you can write a package statement at the top of the java file to specify the package name. Not sure what is the confusion here.

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Sun Dec 02, 2018 10:50 am
by ash4413
Thanks for your reply

we know that class can belong to any package but how comes p?
Is it fixed to take p or any other alphabets can we take?
or share link of any resources

Thanks

Re: About Question enthuware.ocajp.i.v7.2.933 :

Posted: Sun Dec 02, 2018 11:25 am
by admin
A package name can be anything as long as it follows the rules of an identifer.