πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      Which of the following statements is incorrect in

      reference to Java?
      A A constructor has the same name as the class; a method can have any name Correct Answer Incorrect Answer
      B A constructor has no return type (not even void); a method must have a return type (or void) Correct Answer Incorrect Answer
      C A constructor is called automatically when an object is created; a method is called explicitly Correct Answer Incorrect Answer
      D A constructor can be declared with a 'void' return type to indicate it returns nothing Correct Answer Incorrect Answer
      E A constructor can be overloaded (multiple constructors with different parameters); methods can also be overloaded Correct Answer Incorrect Answer

      Solution

      Declaring a constructor with void makes it a method, not a constructor. If no constructor is defined, Java provides a no-argument default constructor that initialises fields to default values (0 for numbers, null for objects, false for boolean). Once any constructor is defined, the default constructor is not automatically provided.

      Practice Next

      Relevant for Exams:

      ask-question