Top 250+ Solved Java Programming MCQ Questions Answer

From 256 to 270 of 285

Q. What is the value of y if x = 2?

a. 2

b. 3

c. 7

d. 9

Q. Two-way selection in Java is implemented using ________.

a. if statements

b. for loops

c. if...else statements

d. sequential statements

  • c. if...else statements

Q. Which of the following will cause a semantic error, if you are trying to compare x to 5?

a. if (x == 5)

b. if (x = 5)

c. if (x <= 5)

d. if (x >= 5)

  • b. if (x = 5)

Q. If class Dog has a subclass Retriever, which of the following is true?

a. Because of single inheritance, Dog can have no other subclasses.

b. Because of single inheritance, Retriever can extend no other class except Dog.

c. The relationship between these classes implies that Dog “is-a” Retriever.

d. The relationship between these classes implies that Retriever “has-a” Dog.

  • b. Because of single inheritance, Retriever can extend no other class except Dog.

Q. If there are three classes: Shape, Circle, and Square, what is the most likely relationship between them?

a. Square is a superclass, and Shape and Circle are subclasses of Square.

b. Shape is a superclass, and Circle and Square are subclasses of Shape.

c. Shape, Circle, and Square are all sibling classes.

d. These three classes cannot be relate

  • b. Shape is a superclass, and Circle and Square are subclasses of Shape.

Q. What is byte code in the context of Java?

a. The type of code generated by a Java compiler

b. The type of code generated by a Java Virtual Machine

c. It is another name for a Java source file

d. It is the code written within the instance methods of a class.

  • a. The type of code generated by a Java compiler

Q. Under what circumstances might you use the yield method of the Thread class

a. To call from the currently running thread to allow another thread of the same or higher priority to run

b. To call on a waiting thread to allow it to run

c. To allow a thread of higher priority to run

d. To call from the currently running thread with a parameter designating which thread should be allowed to run

  • a. To call from the currently running thread to allow another thread of the same or higher priority to run

Q. Which of the following is the correct syntax for suggesting that the JVM performsgarbage collection?

a. System.free();

b. System.setGarbageCollection();

c. System.out.gc();

d. System.gc();

  • d. System.gc();

Q. A class that cannot be a subclass is called as______ class.

a. abstract

b. parent class

c. Final

d. none of these

  • c. Final

Q. When method defined in subclass which has same signature as a method in a super class,it is known as method

a. Overloading

b. Overriding

c. Packing

d. None of these

  • b. Overriding

Q. Which of the following statement is correct?

a. For positive numbers, result of operators >> and >>> are same

b. Java provides two operators to do left shift <<< and <<

c. >> is the zero fill right shift operator

d. >>> is the signed right shift operator

  • a. For positive numbers, result of operators >> and >>> are same

Q. Java language has support for which of the following types of comment ?

a. block, line and javadoc

b. javadoc, literal and string

c. javadoc, char and string

d. single, multiple and quote

  • a. block, line and javadoc

Q. Consider the following program:import myLibrary.*; public class ShowSomeClass { // code for the class... } What is the name of the java file containing this program?

a. myLibrary.java

b. ShowSomeClass.java

c. ShowSomeClass

d. ShowSomeClass.class 1.

  • b. ShowSomeClass.java

Q. Which of the following is TRUE?

a. In java, an instance field declared public generates a compilation error.

b. int is the name of a class available in the package java.lang

c. Instance variable names may only contain letters and digits.

d. A class has always a constructor (possibly automatically supplied by the java compiler).

  • d. A class has always a constructor (possibly automatically supplied by the java compiler).
Subscribe Now

Get All Updates & News