1. Which of these keywords is used to define a package in Java?
a) pkg
b) Pkg
C) package
d) Package
Answer: C
Explanation: None.
2. Which of these nomenclature and visibility controls is a mechanism for a class and its contents?
a) thing
b) package
C) interface
d) None of the mentions.
Answer: B
Explanation: There are both package naming and visibility control mechanisms. We can define a class inside a package that is not accessible by code outside the package.
3. Which one of this accesses can be used for a class so that its members can be accessed by a different class in the same package?
a) public
b) protected
c) no modifier
D) all mentioned
Answer: D
Explanation: Either we can use public, protected or we can name the class without any specifics.
4. Which of these access specifiers can be used for a class so that its members can be accessed by a different class in different packages?
a) public
b) protected
C) private
D) no modifier
Answer: A
Explanation: None.
5. Which of the following is the correct way to import the entire package 'pkg'?
a) Import pkg.
b) import pkg.
c) import pkg. *
d) Import pkg. *
Answer: C
Explanation: The operator * is used to import the entire package.
6. Which of the following is an incorrect statement about a package?
a) The package defines a namespace in which classes are stored
B) One package may include other packages
c) Java uses the file system directory to store packages
D) A package can be renamed without changing the name of the directory in which the classes are stored
Answer: D
Explanation: A package can only be named after renaming the directory in which the classes are stored.
7. Which of the following packages stores all standard Java classes?
a) Lang
b) Java
C) usage
d) java.packages
Answer: B
Explanation: None.
8. What will be the output of the following Java program?
Package pkg;
Class performance
{
Int x;
Show void ()
{
If (x> 1)
System.out.print (x + "");
}
}
Class package
{
public static void main (String [] args[])
{
Display [] arrest = new display [3];
for (int i = 0; i <3; i ++)
arr [i] = new display ();
arr [0] .x = 0;
arr [1] .x = 1;
arr [2] .x = 2;
for (int i = 0; i <3; ++ i)
Arrival [i] .show ();
}
}
Note: The package.class file is in the directory pkg;
A) 0
B) 1
C) 2
d) 0 1 2
Answer: C
Explanation: None.
Output: $ java package. Java $ java package
9. What will be the output of the following Java program?
Package pkg;
Class production
{
public static void main (String [] args[])
{
StringBuffer s1 = new StringBuffer ("Hello");
s1.setCharAt (1, x);
Println (s1);
}
}
A) xlo
b) xxxxx
C) Hxllo
D) Hexlow
Answer: C
Explanation: None.
Output: $ javac output.java $ java output Hxllo
10. What will be the output of the following Java program?
Package pkg;
Class production
{
public static void main (String [] args[])
{
StringBuffer s1 = new StringBuffer ("Hello World");
s1.insert (6, "good");
Println (s1);
}
}
Note: Output.class file directory is not in pkg.
A) halogoodworld
B) Helgudo World
C) compilation error
D) runtime error
Answer: D
Explanation: Since the output.class file is not in the directory pkg in which the class output is defined, the program will not run.
Output: $ javac output.java $ java cannot find output file output.class
11. Which keyword is used to define interfaces in Java?
a) interface
b) interface
c) intf
d) Diff
Answer: A
Explanation: None.
12. Which of the following can be used to completely abstract a class from its implementation?
a) objects
b) package
C) interface
D) None of the Mention
Answer: C
Explanation: None.
13. Which of these access specifications can be used in these interfaces?
a) public
b) protected
C) private
D) all mentioned
Answer: A
Explanation: An interface's access spacier is either public or not specified. When no access spacier is used then the default access spacier is used due to which the interface is only available to the other members of the package in which it is declared, when declared public it can be used in any code. Can be used by
14. Which of these keywords is used by a class to use an already defined interface?
a) import
b) import
C) tools
d) Implements
Answer: C
Explanation: The interface is inherited by a class.
15. Which of the following is the correct way for a class manager to implement interface pay?
A) Extension of class manager salary {}
B) class manager implements salary {}
C) class manager import salary {}
d) none of the mentioned
Answer: B
Explanation: None.
C) private
D) all mentioned
Answer: A
Explanation: An interface's access spacier is either public or not specified. When no access spacier is used then the default access spacier is used due to which the interface is only available to the other members of the package in which it is declared, when declared public it can be used in any code. Can be used by
14. Which of these keywords is used by a class to use an already defined interface?
a) import
b) import
C) tools
d) Implements
Answer: C
Explanation: The interface is inherited by a class.
15. Which of the following is the correct way for a class manager to implement interface pay?
A) Extension of class manager salary {}
B) class manager implements salary {}
C) class manager import salary {}
d) none of the mentioned
Answer: B
Explanation: None.