State three differences between a constructor and a method.
Constructors
Original Khojo Papers practice question — not from a past board paper.
A default constructor takes no arguments and gives the instance variables their default or a fixed initial value. A parameterised constructor takes arguments and initialises the object with the values passed. A copy constructor takes an object of the same class as its argument and initialises the new object with that object's values.
No citable source has been recorded for this record. Treat it as practice material, not as fact.
Writing any constructor removes the compiler-supplied default one.
From the same topic and chapter, at a similar level.
State three differences between a constructor and a method.
Constructors
What is constructor overloading? Give one situation in which it is useful.
Constructors
Write a class Rectangle with a parameterised constructor and a method to return its area.
Constructors
What is a constructor? State three of its characteristics.
Constructors
Explain the ternary operator in Java and rewrite "if (a > b) max = a; else max = b;" using it.
Operators and Expressions in Java
What is the output of: String s = "Examination"; System.out.println(s.length() + " " + s.substring(0, 4) + " " + s.toUpperCase().charAt(2));
String Handling