Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User defined and default constructor?

Ok I am trying to wrap my head around this:

  1. Write an application that creates a class for the student object with the following attributes: Student Number, Name, Address, Phone No., and Course.

Write a test program that sets and gets each attribute in the class. The test program should also display all of the attributes in the class.

  1. Using the student class and its attributes from the previous question, write an application (extend the previous program) that includes both a user-defined and default constructor.

Write a test program to demonstrate the use of both constructors.

This is a work-sheet from college, for some revision on Objects in Java.

The part that troubles me is the one where it asks to have both user-defined and default constructor?

I was under impression it was impossible to do it? Because if you don't provide a constructor yourself, JVM will provide one (default constructor?). But if you define any constructor, then default one becomes unavailable?

Is this just poorly worded task, or could it mean something else?

like image 533
galdikas Avatar asked Dec 26 '22 12:12

galdikas


1 Answers

I'm pretty sure whoever created the work-sheet meant "No-arg constructor" instead of "Default constructor".

You can't technically create the Default constructor (since this is done for you by the compiler), but you can explicitly create the no-arg constructor (which functionally is the same).

So, yes, poorly worded task.

like image 126
J Steven Perry Avatar answered Jan 12 '23 05:01

J Steven Perry