Programming MCQs

MCQ On Inheritance, Package & Interface In Java

Pinterest LinkedIn Tumblr

Here are the collections of MCQ on inheritance, package & interface in java includes multiple-choice questions on defining inheritance, packages and interfaces. You will find here MCQ questions on three types of access specifiers and the final keyword. It also includes creating a package, adding more classes to a package, and accessing the contents of a package.

1. ………………… is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
A) Mutual Exclusion
B) Inheritance
C) Package
D) Interface

2. ……………….. helps to extend the functionality of an existing by adding more methods to the subclass.
A) Mutual Exclusion
B) Inheritance
C) Package
D) Interface

3. The variables, methods, and inner classes that are declared ………………… are accessible to the sub-classes of the class in which they are declared.
A) private
B) public
C) protected
D) friend

4. State whether the following statements about the advantages of organizing classes into packages are True or False.
i) Two classes in two different packages can not have the same name.
ii) The classes contained in the packages of other programs can be easily reused.
A) True, False
B) False, True
C) True, True
D) False, False

5. ………………….. package in java contents language utility classes such as vectors, hash tables, random numbers date etc.
A) java.util
B) java.awt
C) java.net
D) java.lang

6. …………………….. package in java contents set of classes for implementing graphical user interface, which includes classes for windows, buttons, lists, menus and so on.
A) java.util
B) java.awt
C) java.net
D) java.lang

7. State whether the following statements are True or False.
i) When present, package must be the first non-comment statement in the file. 
ii) When we implement an interface method, it should be declared as public.
A) True, False
B) False, True
C) True, True
D) False, False

8. Which keyword can protect a class in a package from accessibility by the classes outside the package?
i) private              ii) protected                 iii) final
A) i only
B) ii only
C) iii only
D) None of the above

9. A package is a collection of
A) Classes
B) interfaces
C) editing tools
D) classes and interfaces

10. Package P1 contains the following code

package P1;
public class student {Body of Student}
Class Test {Body of Test}

Now consider the following code;

import P1.*;
Class Result{
student S1;
Test t1;
}

This code compile because
A) Class result should be declared public.
B) Student class is not available
C) Test class is not available
D) Result body is not fully defined


11. Which of the following classes in Java.io package defines a method to delete a file.
A) Stack
B) File
C) String
D) Vector

12. For a valid file object reference, we can create a new file using the following classes defined in Java.io package.
i) FileOutputStream
ii) RandomAccessFile
iii) DataInput
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii

13. The Date class includes within ………………….. package.
A) java.io
B) java.awt
C) java.net
D) java.util

14. Which of the following classes are included in java.awt package.
i) Font                 ii) Frame             iii) Float                 iv) File
A) i and ii only
B) ii and iii only
C) iii and iv only
D) i and iv only

15. Which of the following sub-classes are included in object class in Java.
i) Dictionary       ii) Date            iii) Label                iv) Thread
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) i, ii and iv only

16. An …………………. is an incomplete class that requires further specification.
A) abstract class
B) final class
C) static class
D) super class

17. A class can be declared as ………………………. if you do not want the class to be sub-classed.
A) abstract
B) final
C) static
D) super

18. The …………………….. keyword is used to derive a class from a super-class.
A) adds
B) extends
C) duplicate
D) inherit

19. If a class that implements an interface does not implement all the methods of the interface, then the class becomes a/an …………………….. class. 
A) abstract
B) final
C) static
D) super

20. By convention, java packages begin with ………………. letters while all the class names begin with an ………………… letter.
A) uppercase, uppercase
B) lowercase, lowercase
C) uppercase, lowercase
D) lowercase, uppercase

Answers

1. B) Inheritance
2. B) Inheritance
3. C) protected
4. B) False, True
5. A) java.util
6. B) java.awt
7. C) True, True
8. D) None of the above
9. D) classes and interfaces
10. C) Test class is not available
11. B) File
12. A) i and ii only
13. D) java.util
14. A) i and ii only
15. D) i, ii and iv only
16. A) abstract class
17. B) final
18. B) extends
19. A) abstract
20. D) lowercase, uppercase

Read Next: Top 20 MCQ Questions On Streams In Java
Read More:  Java MCQ Questions

Author

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Comments are closed.