The code below shows some of the text for a class called City.

Now write a complete public constructor with two formal parameters:
a String parameter called cityName, and an int parameter called cityPop.
Your code should initialize the name attribute of the class to the value of
cityName, and it should intitialize the population attribute to the value
of cityPop.

public class City {

private String name;
private int population;

1 answer

Constructors is a method that should (generally) be public, have no type and have their names correspond to the name of the class (City in this case).

So you would begin like this:

public City()
{
}
Now you can do the rest of the requirements including:
1. insert two parameters including type, for example String cityName, and int cityPop (they should be different from those of the state variables.
2. Assign the values of these parameters to the state variable name and population.
And, voilĂ , the constructor will be complete.
Similar Questions
  1. This is the problem:The following HTML code fragment contains a reference to an image file called frog.gif and with alternate
    1. answers icon 7 answers
    1. answers icon 2 answers
    1. answers icon 1 answer
  2. python1. Write a constructor for a class called Book that will have a title, author, and price. 2. Describe why the following
    1. answers icon 1 answer
more similar questions