1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
deff fn [24]
3 years ago
15

Name the different types of constructors that a designer can provide in a class. Provide an example with a class showing many co

nstructors.
Computers and Technology
1 answer:
Marrrta [24]3 years ago
8 0
By default, if you do not implement a constructor, the compiler will use an empty constructor (no parameters and no code). The following code will create an instance of the MyObject class using the default constructor. The object will have the default vauesfor all the attributes since no parameters were given.

MyObject obj = new MyObject();

Another type of constructor is one with no parameters (no-arg constructor). It is similar to the default, except you actually create this constructor. The contents of the the constructor may include anything. To call a no-arg constructor, use the same line of code as above. The constructor can look like the one below:

public MyObject() {
System.out.println("This is a no-arg constructor");
}

Lastly there is the parameterized constructor. This type of constructor takes in parameters as inputs to assign to values in the newly created object. You call a parameterized constructor as follows:

MyObject obj = new MyObject("Bob", 20);

The constructor will look like this:

public MyObject(String name, int age) {
this.name = name;
this.age = age;
}

In the constructor, the keyword "this" refers to the object, so this.name is a private global variable that is being set equal to the inputted value for name, in this case "Bob".

Hope this helps!
You might be interested in
At Chicago Cubs games, residents across the street from Wrigley Field can watch the game from their apartment windows. Many of t
miv72 [106K]

Answer:

There is a free-rider problem.

Explanation:

A free-rider is demonstrated as the economic problem in which the people continue to access or consume a resource without working or paying to ensure the upkeep of the resource.

As per the description, the given economic problem would be characterized as 'free-rider problem' as the resources are being consumed by the people('watch the game') without contributing a penny for it. This implies the burden on limited resources as people are not fairly paying to upkeep the resource and the resources tend to be overused or degenerated. Thus, <u>'</u><u>the free-rider'</u> problem has been demonstrated here.

7 0
2 years ago
What does DKIM stand for?
zheka24 [161]
Domain Keys Identified Mail is the answer:)
4 0
3 years ago
Read 2 more answers
In addition to the decimal number system, the number systems used most often in PLC operationand programming are ________.
otez555 [7]

Answer: PLC uses:

1. Decimal Number system

2. Binary Number system.

3. Octal Number system.

4. Hexadecimal Number system.

5. Binary Coded Decimal Number system.

6. Negative Number system.

7. Number Conversations.

Explanation: The other numbers the Programmable Logic Controller(PLC) uses aside the decimal number system are:

1. Binary Number system.

2. Octal Number system.

3. Hexadecimal Number system.

4. Binary Coded Decimal Number system.

5. Negative Number system.

6. Number Conversations.

7 0
3 years ago
Need help with a program to search to sort elements in an array.(increasing or decreasing order)
astraxan [27]

This is for Python

numbers = [7, 3, 6, 9, 0]

print(numbers.sort())

Output: [0, 3, 6, 7, 9]

numbers = [7, 3, 6, 9, 0]

print(numbers.sort(reverse = True))

Output: [9, 7, 6, 3, 0]

7 0
3 years ago
Algorithm and flowchart to find the perimeter and area of square​
kupik [55]

Answer:

I can give you the perimeter "algorithm" but not the flowchart.

Here you go:

p = w * 4

p = perimiter,

w = width/height

4 = the amount of sides needed.

perimeter = width * 4

to include both width and height, we would instead use:

perimeter = 2(width+height)

This also works with rectangles ^

--------------------------------------------------------------------------

To find an area, it is just width * height. This is also compatible with rectangles.

4 0
3 years ago
Other questions:
  • Which is an example of an input device?
    15·2 answers
  • The help desk received a call from a user who cannot get any print jobs to print on the locally shared printer. While questionin
    10·2 answers
  • Write a program in java that reads each line in a file, reverses its characters, and writes the resulting line to another file
    15·1 answer
  • Find a 95% confidence interval for the mean failure pressure for this type of roof panel.The article "Wind-Uplift Capacity of Re
    7·1 answer
  • Is it important for a writer to include voice and point of view in writing because...<br> Plz help
    10·1 answer
  • What does cmyk stand for?
    5·2 answers
  • In C!!
    11·1 answer
  • Which online note-taking device allows students to clip a page from a website and reuse it later?
    13·2 answers
  • You are creating a query for a website. The query
    5·1 answer
  • can you guys plz answeer this i need help rrly bad and plz no viruses or links or answers that have nun to do with this
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!