Packages(Computer Science > Java Program ) Questions and Answers
Explanation:-
Answer: Option D. -> Runtime errorSince output.class file is not in the directory pkg in which class output is defined, program will
not be able to run.
output:
$ javac output.java
$ java output
can not find file output.class
Explanation:-
Answer: Option C. -> HxlloNone.
Output:
$ javac output.java
$ java output
Hxllo
Question 3.
What is the output of this program?
package pkg;
class display {
int x;
void show() {
if (x > 1)
System.out.print(x + " ");
}
}
class packages {
public static void main(String args[]) {
display[] arr=new display[3];
for(int i=0;i
- 0
- 1
- 2
- 0 1 2
Explanation:-
Answer: Option C. -> 2None.
Output:
$ javac packages.java
$ java packages
2
Explanation:-
Answer: Option B. -> javaNone.
Explanation:-
Answer: Option D. -> A package can be renamed without renaming the directory in which the classes are stored.A package can be renamed only after renaming the directory in which the classes are stored.
Explanation:-
Answer: Option C. -> import pkg.*Operator * is used to import the entire package.
Explanation:-
Answer: Option A. -> PublicNone.
Explanation:-
Answer: Option D. -> All of the mentionedEither we can use public, protected or we can name the class without any specifier.
Explanation:-
Answer: Option C. -> packageNone.
Explanation:-
Answer: Option B. -> PackagesPackages are both naming and visibility control mechanism. We can define a class inside a
package which is not accessible by code outside the package.