Java Interviews MCQs - Quiz

  • 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 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 Multiple inheritance and operator overloading
  • B Garbage collection and exception handling
  • C Polymorphism and encapsulation
  • D Dynamic memory allocation and function templates
  • 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 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 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.
  • A The "super" keyword is used to refer to the immediate subclass of a class.
  • B The "super" keyword is used to invoke the superclass constructor or method.
  • C The "super" keyword is used to specify a superclass in a multiple inheritance scenario.
  • D The "super" keyword is used to define static variables in a class.
  • A Yes, both overloading and overriding are possible for static methods in Java.
  • B No, static methods cannot be overloaded or overridden in Java.
  • C Overloading is possible but overriding is not allowed for static methods in Java.
  • D Overriding is possible but overloading is not allowed for static methods in Java.
  • A Yes, private methods can be overridden in Java.
  • B No, private methods cannot be overridden in Java.
  • C Private methods can be overridden but only within the same class.
  • D Private methods cannot be overridden but can be accessed using reflection.