99
78k

610+ Java Programming Solved MCQs

These multiple-choice questions (MCQs) are designed to enhance your knowledge and understanding in the following areas: Bachelor of Computer Applications (BCA) , Bachelor of Science in Computer Science (BSc CS) , Master of Computer Applications (MCA) , Programming Languages .

151.

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)
Answer» B. if (x = 5)
152.

How many constructors does the class Exception have?

A. 0
B. 1
C. 2
D. 3
Answer» C. 2
153.

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.
Answer» B. Because of single inheritance, Retriever can extend no other class except Dog.
154.

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 related.
Answer» B. Shape is a superclass, and Circle and Square are subclasses of Shape.
155.

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.
Answer» A. The type of code generated by a Java compiler
156.

What is garbage collection in the context of Java?

A. The operating system periodically deletes all of the java files available on the system.
B. Any package imported in a program and not used is automatically deleted.
C. When all references to an object are gone, the memory used by the object is automatically reclaim
Answer» C. When all references to an object are gone, the memory used by the object is automatically reclaim
157.

What is different between a Java applet and a Java application?

A. An application can in general be trusted whereas an applet can't.
B. An applet must be executed in a browser environment.
C. An applet is not able to access the files of the computer it runs on
D. All of the above
Answer» D. All of the above
158.

JAR stands for?

A. Java Archive
B. Java Archive Runner
C. Java Application Runner
D. None of the above
Answer» A. Java Archive
159.

What are the pillars of OOPS concept?

A. Abstraction, Inheritance, Encapsulation, Polymorphism
B. Atomicity, Inheritance, Encapsulation, Polymorphism
C. Abstraction, Inheritance, Polymorphism
D. None of the Above
Answer» A. Abstraction, Inheritance, Encapsulation, Polymorphism
160.

What is the default buffer size used by any buffered class?

A. 128 bytes
B. 256 bytes
C. 512 bytes
D. 1024 bytes
Answer» C. 512 bytes
161.

Which class cannot be a subclass in java

A. Abstract class
B. Parent class
C. Final class
D. None of above
Answer» C. Final class
162.

Why we use array as a parameter of main method

A. It is syntax
B. Can store multiple values
C. Both of above
D. None of above
Answer» B. Can store multiple values
163.

What is process of defining two or more methods within same class that have same name but different parameters declaration?

A. Method overloading
B. Method overriding
C. Method hiding
D. None of the mentioned
Answer» A. Method overloading
164.

Which of these can be overloaded?

A. Methods
B. Constructors
C. Both a & b
D. None of the mentioned
Answer» C. Both a & b
165.

Which of these is correct about passing an argument by call-by-value process?

A. Copy of argument is made into the formal parameter of the subroutine.
B. Reference to original argument is passed to formal parameter of the subroutine.
C. Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument.
D. Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument.
Answer» A. Copy of argument is made into the formal parameter of the subroutine.
166.

What is the process of defining a method in terms of itself that is a method that calls itself?

A. Polymorphism
B. Abstraction
C. Encapsulation
D. Recursion
Answer» D. Recursion
167.

Which of the following statements are incorrect?

A. Default constructor is called at the time of declaration of the object if a constructor has not been defined.
B. Constructor can be parameterized.
C. Finalize() method is called when a object goes out of scope and is no longer need
Answer» C. Finalize() method is called when a object goes out of scope and is no longer need
168.

What is the stored in the object obj in following lines of code? box obj;

A. Memory address of allocated memory of object.
B. NULL
C. Any arbitrary pointer
D. Garbage
Answer» B. NULL
169.

Which of the following is a valid declaration of an object of class Box?

A. Box obj = new Box();
B. Box obj = new Box;
C. obj = new Box();
D. new Box obj;
Answer» A. Box obj = new Box();
170.

Which of this statement is incorrect?

A. Every class must contain a main() method.
B. Applets do not require a main() method at all.
C. There can be only one main() method in a program.
D. main() method must be made public.
Answer» A. Every class must contain a main() method.
171.

Which of the following statements is correct?

A. Public method is accessible to all other classes in the hierarchy
B. Public method is accessible only to subclasses of its parent class
C. Public method can only be called by object of its class.
D. Public method can be accessed by calling object of the public class.
Answer» A. Public method is accessible to all other classes in the hierarchy
172.

Program which executes applet is known as

A. applet engine
B. virtual machine
C. JVM
D. None of above
Answer» A. applet engine
173.

You read the following statement in a Java program that compiles and executes. submarine.dive(depth); What can you say for sure?

A. Depth must be an int
B. Dive must be a method.
C. Dive must be the name of an instance fie
Answer» B. Dive must be a method.
174.

Which is true about an anonymous inner class?

A. It can extend exactly one class and implement exactly one interface.
B. It can extend exactly one class and can implement multiple interfaces.
C. It can implement multiple interfaces regardless of whether it also extends a class.
D. none
Answer» B. It can extend exactly one class and can implement multiple interfaces.
175.

If a thread is to be declared as a daemon thread, it must be declared before

A. start method
B. run method
C. stop method
D. none
Answer» A. start method
176.

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
Answer» A. To call from the currently running thread to allow another thread of the same or higher priority to run
177.

Which of the following is the correct syntax for suggesting that the JVM performs garbage collection?

A. System.free();
B. System.setGarbageCollection();
C. System.out.gc();
D. System.gc();
Answer» D. System.gc();
178.

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

A. abstract
B. parent class
C. Final
D. none of these
Answer» C. Final
179.

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
Answer» B. Overriding
180.

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
Answer» A. For positive numbers, result of operators >> and >>> are same
181.

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
Answer» A. block, line and javadoc
182.

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.
Answer» B. ShowSomeClass.java
183.

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).
Answer» D. A class has always a constructor (possibly automatically supplied by the java compiler).
184.

Consider the following code snippet String river = new String(“Columbia”); System.out.println(river.length()); What is printed?

A. 6
B. 7
C. 8
D. Columbia
Answer» C. 8
185.

What is different between a Java applet and a Java application?

A. An application can in general be trusted whereas an applet can't.
B. An applet must be executed in a browser environment.
C. An applet is not able to access the files of the computer it runs on
D. (A), (B) and (C).
Answer» D. (A), (B) and (C).
186.

You read the following statement in a Java program that compiles and executes. submarine.dive(depth); What can you say for sure?

A. depth must be an int
B. dive must be a method.
C. dive must be the name of an instance fie
Answer» B. dive must be a method.
187.

Consider public class MyClass{ public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write?

A. MyClass mc = new MyClass();
B. MyClass mc = MyClass();
C. MyClass mc = MyClass;
D. MyClass mc = new MyClass; 7. E. It can't be done. The constructor of MyClass should be defined as public void MyClass(){/*code*/}
Answer» A. MyClass mc = new MyClass();
188.

In Java Inheritance

A. all fields of a class are private
B. all fields of a class are protected
C. a new class is derived from an existing class
D. none of these above
Answer» C. a new class is derived from an existing class
189.

What happens in a method if there is an exception thrown in a try block but there is no catch block following the try block?

A. The program ignores the exception.
B. The program will not compile without a complete try/catch structure.
C. The program terminates immediately.
D. The program throws an exception and proceeds to execute the finally block.
Answer» D. The program throws an exception and proceeds to execute the finally block.
190.

The class RuntimeException is the superclass of which of the following classes?

A. NullPointerException
B. NoSuchMethodException
C. IllegalAccessException
D. NoSuchFileException
Answer» A. NullPointerException
191.

How many finally blocks can there be in a try/catch structure?

A. There must be 1.
B. There can be 1 following each catch block.
C. There can be 0 or 1 following the last catch block.
D. There is no limit to the number of finally blocks following the last catch block.
Answer» C. There can be 0 or 1 following the last catch block.
192.

Which of the following statements is NOT true about creating your own exceptions?

A. Typically, constructors are the only methods that you include when you define your own exception class.
B. The exception class that you define extends either the class Throwable or one of its subclasses.
C. If you have created an exception class, you can define other exception classes extending the definition of the exception class you creat
Answer» B. The exception class that you define extends either the class Throwable or one of its subclasses.
193.

What can a method do with a checked exception?

A. Check the exception or ignore it.
B. Return the exception to the sender or handle it in a catch block.
C. Throw the exception to the method that called this method, or handle the exception in a catch block.
D. Handle the exception in the try block or handle the exception in the catch block.
Answer» C. Throw the exception to the method that called this method, or handle the exception in a catch block.
194.

Which of the following is an exception thrown by the methods of the class String?

A. NullPointerException
B. FileNotFoundException
C. NoSuchElementsException
D. NumberFormatException
Answer» A. NullPointerException
195.

Which of the following statements is true?

A. The class Exception, which is derived from the class Object, is the superclass of the class Throwable.
B. The class Throwable, which is derived from the class Exception, is the superclass of the class Object.
C. The class Throwable, which is derived from the class Object, is the superclass of the class Exception.
D. None of these
Answer» C. The class Throwable, which is derived from the class Object, is the superclass of the class Exception.
196.

A message string is returned by which method of an Exception object?

A. printMessage()
B. getMessage()
C. printStackTrace()
D. traceMessage()
Answer» B. getMessage()
197.

When is a finally {} block executed?

A. Only when an exception is thrown by a try block
B. Only when there are no exceptions thrown
C. At the end of a program
D. Always after the execution of a try block, regardless of whether or not an exception is thrown
Answer» D. Always after the execution of a try block, regardless of whether or not an exception is thrown
198.

When does Exceptions in Java arises in code sequence?

A. Run Time
B. Compilation Time
C. Can Occur Any Time
D. None of the mentioned
Answer» A. Run Time
199.

Which of these keywords is not a part of exception handling?

A. try
B. finally
C. thrown
D. catch
Answer» C. thrown
200.

Which of these keywords is used to manually throw an exception?

A. try
B. finally
C. throw
D. catch
Answer» C. throw

Done Studing? Take A Test.

Great job completing your study session! Now it's time to put your knowledge to the test. Challenge yourself, see how much you've learned, and identify areas for improvement. Don’t worry, this is all part of the journey to mastery. Ready for the next step? Take a quiz to solidify what you've just studied.