C Programming Multiple Choice Questions (MCQ) | IT Developer <?php echo $page_title; ?>
IT Developer

Java Programming Multiple Choice Questions (MCQ)

Introduction to Java - Multiple Choice Questions (MCQ) - Set 3



Share with a Friend

Multiple Choice Questions


Java - Introduction to Java - Multiple Choice Questions (MCQ) - Set 3

11. Which keyword is used to define class?
A). define
B). class
C). struct
D). object
View Answer
Correct: B

 

Explanation

The correct keyword used to define a class is B). class.


In major object-oriented programming languages, this keyword serves as the standard for declaring a class: 

  • Java:The class keyword is essential for creating every line of code, as all Java code must exist within a class.
  • Python:It is used to create a blueprint for objects, bundling data and functionality together.
  • C++:It defines a user-defined data type that holds data members and member functions.
  • C#: A class declaration must begin with the classkeyword followed by the identifier. 

Why the other options are incorrect:


A). define: Primarily used in languages like C/C++ to create macros or in Python (as def) to define functions.

C). struct:Used in C to define structures and in C++ as an alternative for declaring classes with default public access.

D). object:This is an instance created from a class, not a keyword for defining the class itself.

 

 



12. Entry point of Java program:
A). start()
B). main()
C). run()
D). init()
View Answer
Correct: B

 

Explanation

The correct answer is B). main()

 

In Java, the main() method is the standard entry point where the Java Virtual Machine (JVM) begins executing a standalone application. 

 

Key Characteristics of the Entry Point:

 

  • Required Signature: For the JVM to recognize it as the starting point, it must be defined exactly as public static void main(String[] args).
  • Execution: When a program is launched via the java command, the JVM loads the specified class and invokes its main()

  • Purpose of Keywords:
    • public: Allows the JVM to access the method from outside the class.
    • static: Enables the JVM to call the method without first creating an instance (object) of the class.
    • void: Indicates that the method does not return any value to the JVM after finishing execution. 

Comparison of Other Options:


  • start(): Used to begin the execution of a thread or to start an applet.
  • run(): The entry point for logic within a separate Thread or Runnable task.
  • init(): Historically used as the first method called when initializing a Java Applet. 

 

 



13. Java is compiled into:
A). Machine code
B). Bytecode
C). Assembly
D). Binary
View Answer
Correct: B

 

Explanation

The correct answer is : B). Bytecode

 

  • Java Bytecode: When you run the Java compiler (javac), it translates your human-readable source code into an intermediate, platform-independent format called Java Bytecode.
  • Class Files: This bytecode is saved on the disk with a .class
  • Role of the JVM: The Java Virtual Machine (JVM)then loads these class files and executes the bytecode by either interpreting it or using a Just-In-Time (JIT) compiler to convert it into native machine code specific to the host operating system.
  • Platform Independence: This two-step process allows Java to follow the "Write Once, Run Anywhere" (WORA) principle, as the same bytecode can run on any system that has a compatible JVM installed

 

 



14. Which is not a Java feature?
A). Platform independent
B). Secure
C). Pointer-based
D). Robust
View Answer
Correct: C

 

Explanation

The correct answer is C). Pointer-based

 

The following are established features of Java:

  • Platform independent: Java code is compiled into bytecode that can run on any system with a Java Virtual Machine (JVM).
  • Secure: Java provides a secure environment by using a bytecode verifierand avoiding explicit pointers that could allow unauthorized memory access.
  • Robust: Java emphasizes reliability through strong memory management, automatic garbage collection, and comprehensive exception handling. 
  • Pointer-basedis not a feature because Java deliberately omits traditional pointer support (such as pointer arithmetic) found in languages like C and C++ to ensure safety and simplicity. 

 

 



15. Java uses which memory management?
A). Manual
B). Automatic
C). Semi-manual
D). None
View Answer
Correct: B




Explanation

Java uses Automatic memory management. 

 

 B). Automatic

 

Key Details:

  • Java utilizes an automatic memory management system known as Garbage Collection (GC).
  • The Java Virtual Machine (JVM) automatically allocates memory for new objects and deallocates memory when objects are no longer in use, which removes the need for manual memory management (like in C or C++).
  • Garbage collector runs periodically to identify unreferenced objects and reclaim their memory.