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
You have implemented a network where hosts are assigned specific roles, such as for file sharing and printing. Other hosts acces
yulyashka [42]

<u>Client-server</u> implemented a network where hosts are assigned specific roles, such as for file sharing and printing. Other hosts access those resources but do not host services of their own.

<u>Explanation:</u>

The client-server can be utilized on the web just as on a neighborhood (LAN). Instances of customer server frameworks on the web incorporate internet browsers and web servers, FTP customers and servers, and the DNS. Different hosts get to those assets yet don't have administrations of their own. Since it permits arrange permits numerous PCs/gadgets to interface with each other and offer assets.

5 0
3 years ago
Write a loop to output the word EXAM 99 times
worty [1.4K]

Answer:

Following are the answer for the given question

for(int i=1;i<=99;++i) // for loop

{

cout<<"EXAM"<<endl; // display the word EXAM

}

Explanation:

In this question we using for loop which is iterating 99 times and print the

word "EXAM  " 99 times.

The variable i is initialized by 1 and check the condition if the condition in loop  is true it will execute the loop and print "EXAM" .The loop will executed 99 times when the condition in loop is false then loop become terminated.

Following are the program in c++

#include<iostream>// header file

using namespace std;

int main() // main method

{

for(int i=1;i<=99;++i) // for loop

{

cout<<"EXAM"<<endl; // display the word EXAM

}

   return 0;

}

3 0
2 years ago
What technology allows data to be stored in one place and be retrieved by many systems?
Mice21 [21]
ICloud is one of the many different tech options.
Hope I helped,
 Ms. Weasley
4 0
2 years ago
10. What is "bandwidth"? (
natali 33 [55]

Answer:

ELECTRONICS

a range of frequencies within a given band, in particular that used for transmitting a signal.

2.

the energy or mental capacity required to deal with a situation.

Explanation:

6 0
3 years ago
A check list should be based on that apply to your industry.
frozen [14]
Can you please elaborate? This is as your question isn't very clear.
6 0
3 years ago
Read 2 more answers
Other questions:
  • In the windows firewall, any rules preceded by a __________ checkmark have not been enabled. black gray green red
    13·1 answer
  • Is a fundamental building block of a relational database because this object stores all of the data
    15·1 answer
  • What career cluster does a fish and game warden fall in?
    14·1 answer
  • As the network engineer, you are asked to design an IP subnet plan that calls for three subnets. The largest subnet needs a mini
    14·1 answer
  • A computer operating system software manufacturer invests its profits in creating newer versions of its operating system softwar
    7·1 answer
  • Meaning of ‘integrity of data’
    14·2 answers
  • Where would you go to access frequently used icons?
    12·2 answers
  • PYTHON
    5·1 answer
  • The data source in the document which has the information common to all documents. True or false 
    9·2 answers
  • Brianna is feeling overwhelmed by the amount of digital
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!