About Question enthuware.ocajp.i.v7.2.933 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2.933 :
"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.
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 22
- Joined: Sun Nov 18, 2012 1:51 am
- Location: Moscow
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
try to create an instance of Test1 and you will get an exception ....ETS User wrote: in Eclipse and he work.
-
- Posts: 19
- Joined: Thu Feb 28, 2013 9:47 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
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.
If the file were different the option £public class MyClass{ }" would correct also.
-
- Posts: 1
- Joined: Fri Mar 04, 2016 9:28 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
how it is valid p.util package statement
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
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.
-
- Posts: 31
- Joined: Wed Feb 08, 2017 5:42 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
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.
or can we have public abstract class and inner class non public.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
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.
You can also try it out to confirm.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Thu Jul 26, 2018 7:48 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
Hi there,
how it is valid p.util package statement of option 2?
Can anyone explain it?
thanks in advance
how it is valid p.util package statement of option 2?
Can anyone explain it?
thanks in advance
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
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.
-
- Posts: 4
- Joined: Thu Jul 26, 2018 7:48 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
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
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
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.933 :
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.
Who is online
Users browsing this forum: Bing [Bot] and 220 guests