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
Compared with traditional methods, the entire rapid application development (RAD) process is expanded and, as a result, the new
tensa zangetsu [6.8K]

Answer:

<u>False</u>

Explanation:

Note, the Rapid Application Development (RAD) software development approaches are noteworthy not for its expanded design details but for <u>its simplicity of the software development process.</u>

In other words, the RAD approaches while taking user preferences into the software development process, focuses on making the software design process more flexible, such as by employing the use of prototypes, and less unnecessary details.

5 0
2 years ago
When you are given a set of tables and asked to create a database to store their data, the first step is to ________?
Vlad1618 [11]
Scan   the tables  to make a digital copy of them
6 0
3 years ago
The HTML tag for the smallest heading is​ what​
Gre4nikov [31]

Answer:

The HTML <h1> to <h6> tag is used to define headings in an HTML document. <h1> defines largest heading and <h6> defines smallest heading.

Explanation:

5 0
3 years ago
A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To ac
Vikentia [17]

Answer:

input-year taken 2020

2020 is divisible by 2

output- 2020 is a leap year

3 0
3 years ago
Which protocol resolves logical addresses to physical addresses?
OLga [1]
The answer to this is ARP
4 0
3 years ago
Other questions:
  • Paragraph talking about why i chose bill gates
    10·1 answer
  • One of the most famous ___ licenses is gpl, which ensures that a particular program remains free to distribute and allows its co
    10·1 answer
  • Given positive integer numInsects, write a while loop that prints that number doubled without reaching 100. Follow each number w
    8·1 answer
  • Explain how it is possible for a sequence of packets transmitted through a wide area network to arrive at their destination in a
    14·1 answer
  • Which ofthe following is the most correct statement about the interestsection of the indirect plan for persuasion?
    8·1 answer
  • Which These operating systems use a graphical user interface?
    6·1 answer
  • 3.26 LAB: Leap Year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate a
    15·2 answers
  • How many ways do advertisers determine target audiences ??????
    15·1 answer
  • I store data that the CPU needs. What am I?
    8·2 answers
  • Which tab on the Ribbon contains the command to print a publication?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!