Java Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Java Programming MCQ (Multiple Choice Questions)

 Que-  What will be the output of the following Java code snippet?  int a = random.nextInt(7) + 4;

a. Random number between 4 to 7, including 4 and 7

b. Random number between 4 to 7, excluding 4 and 7

c. Random number between 4 to 10, excluding 4 and 10

d. Random number between 4 to 10, including 4 and 10


Answer- Random number between 4 to 10, including 4 and 10


Que-  Math.random() guarantees uniqueness?

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-FALSE


Que-  What is the signature of Math.random() method?

a. public static double random()

b. public void double random()

c. public static int random()

d. public void int random()


Answer- public static double random()


Que-  Which of these class produce objects with respect to geographical locations?

a. TimeZone

b. Locale

c. Date

d. SimpleTimeZone


Answer- Locale


Que-  Which of these class can generate pseudorandom numbers?

a. Locale

b. Rand

c. Random

d. None of the mentioned


Answer- Random


Que-  Which of these method of Locale class can be used to obtain country of operation?

a. getCountry()

b. whichCountry()

c. DisplayCountry()

d. getDisplayCountry()


Answer- getDisplayCountry()


Que-  Which of these is a method can generate a boolean output?

a. retbool()

b. getBool()

c. nextBool()

d. nextBoolean()


Answer- nextBoolean()


Que-  What is the use of Observable class?

a. It is used to create global subclasses

b. It is used to create classes that other part of the program can observe

c. It is used to create classes that can be accessed by other parts of program

d. It is used to create methods that can be accessed by other parts of program


Answer- It is used to create classes that other part of the program can observe


Que-  Which of these methods is used to notify observer the change in observed object?

a. update()

b. notify()

c. check()

d. observed()


Answer- update()


Que-  Which of these methods calls update() method?

a. notify()

b. observeObject()

c. updateObserver()

d. notifyObserver()


Answer- notifyObserver()


Que-  Which of these methods is called when observed object has changed?

a. setChanged()

b. update()

c. notifyObserver()

d. all of the mentioned


Answer- all of the mentioned


Que-  Which of these classes can schedule task for execution in future?

a. Thread

b. Timer

c. System

d. Observer


Answer- Timer


Que-  Which of these interfaces is implemented by TimerTask class?

a. Runnable

b. Thread

c. Observer

d. ThreadCount


Answer- Runnable


Que-  Which of these package provides the ability to read and write in Zip format?

a. java.lang

b. java.io

c. java.util.zip

d. java.util.zar


Answer- java.util.zip


Que-  Which of these keywords is used to define packages in Java?

a. pkg

b. Pkg

c. package

d. Package


Answer- package


Que-  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.


Answer- Packages


Que-  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. Protected

c. No Modifier

d. All of the mentioned


Answer- All of the mentioned


Que-  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. Protected

c. Private

d. No Modifier


Answer- Public


Que-  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.*


Answer- import pkg.*


Que-  Which of the following is an incorrect statement about packages?

a. Package defines a namespace in which classes are stored

b. A package can contain other package within it

c. Java uses file system directories to store packages

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


Answer- A package can be renamed without renaming the directory in which the classes are stored


Que-  Which of the following package stores all the standard java classes?

a. lang

b. java

c. util

d. java.packages


Answer- java


Que-  Which of these keywords is used to define interfaces in Java?

a. interface

b. Interface

c. intf

d. Intf


Answer- interface


Que-  Which of these can be used to fully abstract a class from its implementation?

a. Objects

b. Packages

c. Interfaces

d. None of the Mentioned


Answer- Interfaces


Que-  Which of these access specifiers can be used for an interface?

a. Public

b. Protected

c. private

d. All of the mentioned


Answer- Public


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

a. import

b. Import

c. implements

d. Implements


Answer- implements


Que-  Which of the following is the correct way of implementing an interface salary by class manager?

a. class manager extends salary {}

b. class manager implements salary {}

c. class manager imports salary {}

d. none of the mentioned


Answer- class manager implements salary {}


Que-  Which of the following is an incorrect statement about packages?

a. Interfaces specifies what class must do but not how it does

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

c. All variables in interface are implicitly final and static

d. All variables are static and methods are public if interface is defined pubic


Answer- All variables are static and methods are public if interface is defined pubic


Que-  Which of the following access specifiers can be used for an interface?

a. Protected

b. Private

c. Public

d. Public, protected, private


Answer- Protected


Que-  Which of the following is the correct way of implementing an interface A by class B?

a. class B extends A{}

b. class B implements A{}

c. class B imports A{}

d. None of the mentioned


Answer- class B implements A{}


Que-  All methods must be implemented of an interface.

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-TRUE


Que-  What type of variable can be defined in an interface?

a. public static

b. private final

c. public final

d. static final


Answer- static final


Que-  What does an interface contain?

a. Method definition

b. Method declaration

c. Method declaration and definition

d. Method name


Answer- Method declaration


Que-  What type of methods an interface contain by default?

a. abstract

b. static

c. final

d. private


Answer- abstract


Que-  What will happen if we provide concrete implementation of method in interface?

a. The concrete class implementing that method need not provide implementation of that method

b. Runtime exception is thrown

c. Compilation failure

d. Method not found exception is thrown


Answer- Compilation failure


Que-  What happens when a constructor is defined for an interface?

a. Compilation failure

b. Runtime Exception

c. The interface compiles successfully

d. The implementing class will throw exception


Answer- Compilation failure


Que-  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


Answer- The interfaceName.variableName needs to be defined


Que-  Which of these package is used for graphical user interface?

a. java.applet

b. java.awt

c. java.awt.image

d. java.io


Answer- java.awt


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

a. java.applet

b. java.awt

c. java.io

d. java.lang.reflect


Answer- java.lang.reflect


Que-  Which of this package is used for handling security related issues in a program?

a. java.security

b. java.lang.security

c. java.awt.image

d. java.io.security


Answer- java.security

Previous Post Next Post