Sail E0 Webinar

MCQs

Total Questions : 8
Question 1. Which of these keywords is used to define packages in Java?
  1.    pkg
  2.    Pkg
  3.    package
  4.    Package
 Discuss Question
Answer: Option C. -> package


package


Question 2. Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?
  1.    Public
  2.    Protected
  3.    No Modifier
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned


Either we can use public, protected or we can name the class without any specifier.


Question 3. Which of these is a mechanism for naming and visibility control of a class and its content?
  1.    Object
  2.    Packages
  3.    Interfaces
  4.    None of the Mentioned.
 Discuss Question
Answer: Option B. -> Packages


Packages are both naming and visibility control mechanism. We can define a class inside a package which is not accessible by code outside the package.


Question 4. Which of these access specifiers can be used for a class so that it's members can be accessed by a different class in the different package?
  1.    Public
  2.    Protected
  3.    Private
  4.    No Modifier
 Discuss Question
Answer: Option A. -> Public


Public


Question 5. Which of the following is correct way of importing an entire package 'pkg'?
  1.    import pkg.
  2.    Import pkg.
  3.    import pkg.*
  4.    Import pkg.*
 Discuss Question
Answer: Option C. -> import pkg.*


Operator * is used to import the entire package.


Question 6. Which of the following package stores all the standard java classes?
  1.    lang
  2.    java
  3.    util
  4.    java.packages
 Discuss Question
Answer: Option B. -> java


java


Question 7. Which of the following is incorrect statement about packages?
  1.    Package defines a namespace in which classes are stored.
  2.    A package can contain other package within it.
  3.    Java uses file system directories to store packages.
  4.    A package can be renamed without renaming the directory in which the classes are stored.
 Discuss Question
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.


Question 8. What is the output of this program?package pkg;class output {public static void main(String args[]){ StringBuffer s1 = new StringBuffer("Hello");s1.setCharAt(1, x);System.out.println(s1);}}
  1.    xello
  2.    xxxxx
  3.    Hxllo
  4.    Hexlo
 Discuss Question
Answer: Option C. -> Hxllo


Hxllo


Latest Videos

Latest Test Papers