Java Interviews MCQs - Quiz

  • A It allows the method to be called without creating an instance of the class.
  • B It ensures that the main method is executed first when the program starts.
  • C It enables the main method to access static variables and methods directly.
  • D All of the above.
  • A The program will fail to compile.
  • B The program will compile and run, but the main method will not be executed.
  • C The program will compile and run, but it will generate a runtime error.
  • D The program will compile and run normally.
  • A Local variables have scope within the block where they are declared.
  • B Instance variables have scope within the class where they are defined.
  • C Class variables (static variables) have scope within the class and its subclasses.
  • D All of the above.
  • A Yes, the main() method can be overloaded in Java.
  • B No, the main() method cannot be overloaded in Java.
  • C Overloading the main() method is possible, but it is considered bad practice.
  • D Overloading the main() method is possible, but it will cause a runtime error.
  • A Object cloning is the process of creating an exact copy of an object.
  • B Object cloning is the process of creating a new object using a copy constructor.
  • C Object cloning is the process of creating a new object with the same reference as the original object.
  • D Object cloning is not supported in Java.
  • A In Java, multiple inheritance is supported, while in C++ it is not.
  • B In C++, multiple inheritance is supported, while in Java it is not.
  • C In Java, all classes inherit from a common superclass, while in C++ they do not.
  • D In C++, classes can have multiple levels of inheritance, while in Java they cannot.
  • A It would lead to ambiguity and confusion during method resolution.
  • B It violates the principles of object-oriented programming.
  • C Java does not support dynamic dispatch based on return types.
  • D All of the above.
  • A A static variable is a variable that is accessible only within the static methods of a class.
  • B A static variable is a variable that is shared among all instances of a class and is not specific to any particular instance.
  • C A static variable is a variable that is declared with the "static" keyword and cannot be changed once assigned a value.
  • D A static variable is a variable that is declared inside a static block in a class.
  • A Java objects are stored in a stack memory.
  • B Java objects are stored in a heap memory.
  • C Java objects are stored in a separate memory space called the "object memory."
  • D Java objects are stored in a cache memory.