0% found this document useful (0 votes)
3 views11 pages

JAVA QB-4

The document is a question bank for Unit-4 covering various topics in Java, including packages, interfaces, access specifiers, and methods. It consists of multiple-choice questions designed to test knowledge on Java programming concepts. Each question provides options for answers, focusing on the syntax and functionality of Java elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

JAVA QB-4

The document is a question bank for Unit-4 covering various topics in Java, including packages, interfaces, access specifiers, and methods. It consists of multiple-choice questions designed to test knowledge on Java programming concepts. Each question provides options for answers, focusing on the syntax and functionality of Java elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

<br>

Question Bank
Unit-4
1. Package in Java is a mechanism to encapsulate a
(a) Classes

(b) Interfaces

(c) Sub Packages

(d) Allof the above

2. Which of these keywords is used to define interfaces in Java?

(a) intf

(b) Intf

(c) interface

(d) Interface

3. Which of these keywords is used to define packages in Java?

(a) pkg

(b) Pkg

(c) package

(d) Package

4. Which of these is a mechanism for naming and visibility control of a class and its content?

(a) Object

(b) Packages

(c) Interfaces

(d) None of the Mentioned.

5. 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?
(a) Public

(b) No Modifier

(c) Protected
<br>

(d) All of the mentioned

6. Which of these access specifiers can be used for a class so that its members can be accessed by a
different class in the different package?
(a) Public

(b) Private

(c) Protected
(d) No Modifier

7. Which of these package is used for graphical user interface?

(a) java.awt

(b) java.applet

(c) java.io

(d) java.awt.image

8. Which of this package is used for analyzing code during run-time?

(a) java.io

(b) java.awt

(c) java.applet

(d) java.lang.reflect

9. Which of this package is used for handling security related issues in a program?

(a) java.security

(b) java.awt. image

(c) java.io.security

(d) java.lang.security

10. An interface in Java is like a 100%

(a) inner class

(b) public class


<br>

(c) abstract class


(d) anonymous class

11. A Java Interface is not considered a class. State True or False.

(a) True

(b) False

12. Which of the following is the correct way of importing an entire package 'pkg'?

(a) import pkg.

(b) Import pkg.

(c) import pkg.*

(d) Import pkg.*

13. Which of the following is an incorrect statement about packages?

(a) A package can contain other package within it

(b) Java uses file system directories to store packages

(c) Package defines a namespace in which classes are stored

(d) A package can be renamed without renaming the directory in which the classes are stored

14. Java interface can contain

(a) Final variables

(b) Abstract methods

(c) Non-abstract methods


(d) Final variables and abstract methods

15. What is the correct way to implement an interface? Example, 'Operation' interface implements
'Add' class.

(a) class Add implements Operation()

(b) class Add extends Operation{}

(c) class Add import Operation()

(d) None of the above


<br>

16. Which of the following is the correct way of implementing an interface A by class B?

(a) class B extends A{}


(b) class B imports A)
(c) class B implements A()
(d) None of the mentioned

17. All methods must be implemented of an interface.

(a) True

(b) False

18. Which of these keywords is used by a class to use an interface defined previously?

(a) import

(b) Import

(c) implements

(d) Implements

19. Which of the following is correct way of implementing an interface salary by class manager?

(a) class manager extends salary ()

(b) class manager imports salary ()

(c) class manager implements salary ()

(d) None of the mentioned.

20. Which of the following is incorrect statement about packages?

(a) Interfaces are specified public if they are to be accessed by any code in the program.

(b) Interfaces specifies what class must do but not how it does.

(c) All variables in interface are implicitly fnaland statie.Public static final regardless

(d) Allvariables are static and methods are public if interface is defined pubic.

21. Can we declare an interface as final?

(a) Yes
<br>

(b) No

22. The fields in an interface are implicitly specified as

(a) Static

(b) Protected
(c) Private

(d) Static and final

23. Which is correct option about java interface?

(a) Object of an interface cannot be created.

(b) An interface can extend another interface.

(c) Interface is used to achieve multiple inheritance in java


(d) Allthe above

24. Java interface is used


t

(a) Achieve abstraction

(b) achieve loos coupling

(c) Implement behaviour of multiple inheritance


(d) Allof the above

25. Which is true statements about an interface in java?


(a) An interface can have constructor

(b) An interface can extend another interface

(c) We can create object of an interface in java


(d) None of these

26. A class inherits an interface using which keyword?

(a) Implements

(b) Extends

(c) Inherit

(d) None
<br>

27. Package names and directory structure are closely related.

(a) True

(b) False

28. An statement can be used to access the classes and interface ofa different package from the
current package.

(a) import

(b) extends
(c) instanceOf

(d) implement

29. Which of the following packages is used to includes classes to create user interface like Button
and Checkbox?
(a) java.io

(b) java.net

(c) java.awt
(d) java.lang

30. Which of the following package stores all the standard java classes?

(a) Java

(b) Lang

(c) Util

(d) Java.packages

31. Which of these class allows us to get real time data about private and protected member of a
class?
(a) java.io

(b) Getinformation

(c) ReflectPermission

(d) MembersPermission
<br>

32. Which of this package is used for invokinga method remotely?

(a) java.rmi

(b) java.awt

(c) java.util

(d) java.applet

33. All Interface methods in Java are by default.

(a) public

(b) abstract

(c) public and abstract


(d) None of the above

34. Java Class implementing an Interface can define a variable with the same name as that of the
A

Interface constant. State True or False.


(a) True

(b) False

35. A Java Interface can not declare constructors. State True or False.

(a) True

(b) False

36. Java 8(Java 1.8) introduced the feature.

(a) Default methods

(b) Default methods

(c) Default and Static methods


(d) None of the above

37. Java Interface DEFAULT methods have with the existing project code. compatibility
(a) Forward

(b) Backward
<br>

(c) Backward and Forward


(d) Not available for this question.

38. Packages that are inside another package are the

(a) packages

(b) subpackages

(c) util subpackages

(d) nested packages

39. What type of variable can be defined in an interface?

(a) public final

(b) static final

(c) public static

(d) private final

40. What will happen if we provide concrete implementation of method in interface?

(a) Compilation failure

(b) Runtime exception is thrown

(c) Method not found exception is thrown


(d) The concrete class implementing that method need not provide implementation of that
method

41. What happens when we access the same variable defined in two interfaces implemented by the
same class?

(a) Compilation failure

(b) Runtime Exception

(c) The JVM is not able to identify the correct variable

(d) The interfaceName.variableName needs to be defined

42. Can "abstract" keyword be used with constructo, Initialization Block, Instance Initialization and
Static Initialization Block. Milo

(a) True
<br>

(b) False

43. A Static method of an Interface should be accessed with and a DOT operator.
(a) Class Name

(b) Interface Name

(c) An object of a concrete class

(d) None of the above

44. What will be the output of the following Java program?

package pkg:

class output
{

public static void main(String argsl])


{

StringBuffer s1 = new StringBuffer("Hello");

s1.setCharAt(1, x);

System.out.println(s1);

(a) xello

(b) XXXXx

(c) Hxllo

(d) Hexlo

45. Which of these is the method which is executed first before execution of any other thing takes
place in a program?

(a) static method

(b) main method

(c) finalize method


(d) private method

46. Which of these can be used to differentiate two or more methods having the same name?
<br>

10

(a) Parameters data type

(b) Return type of method

(c) Number of parameters


(d) Allof the mentioned

47. All Java methods must have a return type. (True / False)
(a) True

(b) False

48. State True or False. A Java method can have the same name as the class name.
(a) True

(b) False

49. Which method can be defined only once in a program?


(a) static method

(b) main method


(c) finalize method

(d) private method

50. Given the following piece of code:

public class School{

public abstract double numberOfStudent();

which of the following statements is true?

(a) Class School must be defined abstract.

(b) The keywords public and abstract cannot be used together.

(c) The method numberOfStudent() in class School must have a body.

(d) You must add a return statement in method numberOfStudent().

51. A Java method is comparable to a in c language.

(a) enum
<br>

11

(b) structure

(c) union

(d) function

52. What is the return type of a method that does not return any value?

(a) int

(c) double

(b) float

(d) void

53. What is the process of defining more than one method in a class differentiated by method
signature?

(a) Function overloading

(b) None of the mentioned

(c) Function doubling

(d) Function overriding

54. Which of the following is a method having same name as that of it's class?
(a) class

(b) finalize

(c) delete
(d) constructor

55. Which of this statement is incorrect?

(a) main() method must be made public

(b) Allobject of a class are allotted memory for the all the variables defined in the class

(c) If a function is defined public it can be accessed by object of other class by inheritation
(d) All object of a class are allotted memory for the methods defined in the class

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy