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
Host A sends two UDP segments to Server S, one to port 1234 and the other to port 2345. Host B sends one UDP segment to Server S
SOVA2 [1]

Answer:

A

Explanation:

8 0
2 years ago
Which one of the following oscilloscope controls is used to move the trace up and down the screen vertically
kakasveta [241]
B. is the answer to this question
3 0
3 years ago
In the original UNIX operating system, a process executing in kernel mode may not be preempted. Explain why this makes (unmodifi
Elena L [17]

Answer:

the preemption is -> The ability of the operating

system to preempt or stop a currently

scheduled task in favour of a higher priority

task. The scheduling may be one of, but not

limited to, process or 1/0 scheduling etc.

Under Linux, user-space programs have always

been preemptible: the kernel interrupts user

space programs to switch to other threads,

using the regular clock tick. So, the kernel

doesn't wait for user-space programs to

explicitly release the processor (which is the

case in cooperative multitasking). This means

that an infinite loop in an user-space program

cannot block the system.

However, until 2.6 kernels, the kernel itself was

not preemtible: as soon as one thread has

entered the kernel, it could not be preempted to

execute an other thread. However, this absence

of preemption in the kernel caused several

oroblems with regard to latency and scalability.

So, kernel preemption has been introduced in

2.6 kernels, and one can enable or disable it

using the cONFIG_PREEMPT option. If

CONFIG PREEMPT is enabled, then kernel code

can be preempted everywhere, except when the

code has disabled local interrupts. An infinite

loop in the code can no longer block the entire

system. If CONFIG PREEMPT is disabled, then

the 2.4 behaviour is restored.

So it suitable for real time application. Only

difference is we don't see many coders using it

5 0
3 years ago
What computer worm was used to sabatoge iran's nuclear program?
Stels [109]
Researches at symantec have uncovered a version of the stuxnet computer virus that was used to attack irans nuclear program in November.
4 0
3 years ago
________ is a hybrid version of Ethernet that uses either 10Base-T, 100Base-T, or 1000Base-T.
Vladimir79 [104]

Answer: ANSWER is B I'm pretty sure

Explanation: hope this help

s :)

7 0
3 years ago
Other questions:
  • This is a free point thing!! I am giving 100 points!! Anyone wanna talk!!!!
    11·2 answers
  • For a wire with a circular cross section and a diameter = 3.00mm calculate the following: (m means meter. mm means millimeter. c
    5·1 answer
  • 1.) what is the minimum number of bits required to represent -3,997 using 2's complement form?
    6·1 answer
  • 1024 Megabytes = ____________
    14·1 answer
  • Write two cin statements to get input values into birthMonth and birthYear. Then write a statement to output the month, a dash,
    7·1 answer
  • How does a search engine use algorithms to provide search results?
    15·2 answers
  • Which ribbon tab is not a default in Outlook 2016's main interface?
    13·2 answers
  • Type the correct answer in the box. Spell the word correctly. A company has its branches spread over five places in a state. It
    14·1 answer
  • The layer of the ISO/OSI responsible for source to destination delivery.
    13·1 answer
  • 8. Give regular expressions with alphabet {a, b} for
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!