> 10 POINTS! JAVA PROGRAMMING SHORT QUESTION?

10 POINTS! JAVA PROGRAMMING SHORT QUESTION?

Posted at: 2014-12-18 
See the picture (it's only 2 questions!!)



A constructor is a function which is only run once right when you create an object of a class. To create and instantiate an object using a constructor is always in the form Class object = new Class(arguments). Here Class(arguments) is the constructor, but since it mentioned "no arguments" in the question, it is simply Circle c = new Circle();

For the second one, remember every function is in the form

accessSpecifier returnType function()

But, a constructor does not have a returnType. It cannot return any value because it is only used to create an object where there is nowhere to return any value. Also, a constructor name must be exactly same as the name of the respective class. Thus, for a constructor:

accessSpecifier class/constructor (arguments)

public Location (String city)

2) Circle c = new Circle();

3) public Location(String city)

See the picture (it's only 2 questions!!)