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
Importance of taking correct body measurement....
drek231 [11]

Taking correct body measurements is of key importance especially to models and future models. So that they remember about the leftover weight in their body from thanksgiving , now when they take correct body measurements , they are aware and will counter such things to be better.

6 0
3 years ago
The following are part of characteristics of a software requirement specification.
marusya05 [52]

Answer:

should there be 'except' in the question?

6 0
3 years ago
For the following 4-bit operation, assuming these register are ONLY 4-bits in size, which status flags are on after performing t
m_a_m_a [10]

Answer:

All flags are On ( c, z , N  )

Explanation:

Given data:

4-bit operation

Assuming 2's complement representation

<u>Determine status flags that are on after performing </u> 1010+0110

    1   1

    1  0   1  0

    0  1   1  0

  1  0 0 0 0

we will carry bit = 1 over

hence C = 1

given that: carry in = carry out there will be zero ( 0 ) overflow

hence V = 0

also Z = 1      

But the most significant bit is  N = 1

8 0
3 years ago
In excel, a number can contain the characters__
KATRIN_1 [288]
Comma and period? You can have numbers like 123,456.78
7 0
3 years ago
How do I do a PowerPoint
kirill115 [55]
It is like this: . You just put a circle and that is a power point
4 0
3 years ago
Read 2 more answers
Other questions:
  • Due to the internal style sheets of some browsers, your website may look different to someone who is using firefox as opposed to
    11·1 answer
  • What type of program would use to create a personal budget?
    14·1 answer
  • Which one of the following rules for selecting a password is the best?
    5·2 answers
  • If you're using the paintbrush tool and want to change the color of the paint being used what should you change
    6·1 answer
  • Two technicians are discussing shielded cable. Technician A says that shielded wires are generally twisted in pairs to cancel th
    14·1 answer
  • Please create C program, the task is to implement a function edoublepowerx that has an input parameter x of floating-point value
    11·1 answer
  • Please as soon as possible
    13·1 answer
  • How was the addition of an improvement over early web design?
    11·1 answer
  • What is the answer only right answers<br>​
    7·2 answers
  • What term is commonly used to refer to HTML formatting?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!