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
Most of the internal operations in a computer use hexagonal numbering true or false
dolphi86 [110]

Answer:

True

Explanation:

The hexadecimal numbering is the most used numeric system for international operations in a computer, in our daily life we use the decimal system but for the CPU use the byte or octet as a basic unit of memory, we need more than 10 digits, and the hexadecimal system has 16, in addition, the binary system is hard to understand.

4 0
3 years ago
When copying a pie chart from Calc or Excel to Impress or PowerPoint, once the chart has been pasted, it cannot be edited.
dem82 [27]
The answer is true
i think
7 0
3 years ago
Read 2 more answers
Which of the following describes colors, spacing, borders, and other effects that change the appearance of a table?
lisabon 2012 [21]
It is the table style that describes colors and spacing borders and other effects that change the appearance of the table
5 0
3 years ago
What is also known as a visual aid in a presentation
kari74 [83]

the answer is slide

I took notes off of plato and it quoted word for word

A slide is a visual aid, also known as a single screen of presentation

:) hope this helps

5 0
3 years ago
Read 2 more answers
Which IDEs support multiple high-level programming languages? Select all that apply.
nata0808 [166]

Answer:

eclipse, xcode, and visual studio

6 0
3 years ago
Read 2 more answers
Other questions:
  • How do you increase the amount of data in a sampled Google Analytics report?
    8·1 answer
  • You have users who connect to the corporate network using their laptops. because these computers often access confidential data,
    9·1 answer
  • When is the bond between the actin and myosin head is broken? when an ATP molecule binds to the myosin head when an ATP molecule
    6·1 answer
  • Book checkout scenario at a library: The Worker tells the System the identity of a patron who wishes to check out books. The Sys
    8·1 answer
  • Obtain a file name from the user, which will contain data pertaining to a 2D array Create a file for each of the following: aver
    5·1 answer
  • 0x400C (in hexadecimal)?
    8·1 answer
  • This problem has been solved!
    8·1 answer
  • Privacy Group of answer choices must be respected if we are to function as complete, self-governing agents is an absolute value
    5·1 answer
  • 19. Fatigue can help improve your reaction time.<br> False<br> O True
    8·2 answers
  • What is speaker?.....​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!