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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

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

Post 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.

admin
Site Admin
Posts: 9476
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Svetopolk
Posts: 22
Joined: Sun Nov 18, 2012 1:51 am
Location: Moscow
Contact:

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

Post by Svetopolk »

ETS User wrote: in Eclipse and he work.
try to create an instance of Test1 and you will get an exception ....

muttley
Posts: 19
Joined: Thu Feb 28, 2013 9:47 am
Contact:

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

Post 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.

namdevpatil93
Posts: 1
Joined: Fri Mar 04, 2016 9:28 am
Contact:

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

Post by namdevpatil93 »

how it is valid p.util package statement

admin
Site Admin
Posts: 9476
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Not sure what you are asking. Could you please explain?
If you like our products and services, please help us by posting your review here.

AndaRO
Posts: 31
Joined: Wed Feb 08, 2017 5:42 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 9476
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

ash4413
Posts: 4
Joined: Thu Jul 26, 2018 7:48 pm
Contact:

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

Post by ash4413 »

Hi there,
how it is valid p.util package statement of option 2?
Can anyone explain it?
thanks in advance

admin
Site Admin
Posts: 9476
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

ash4413
Posts: 4
Joined: Thu Jul 26, 2018 7:48 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 9476
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

A package name can be anything as long as it follows the rules of an identifer.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests