logo

Crowdly

// import ALL useful classes import java.util.*; class lamp { int static c...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

// import ALL useful classes

import java.util.*;

class lamp {

int static count = 0;

public int id;

public static List<lamp> Lamps = new ArrayList<lamp>();

public lamp() {

if (Lamps.size() >= 10) {

throw new NullPointerException("It is impossible to have more than 10 lamps!");

}

// give every instance an unique id

this.id = count++;

Lamps.add(this);

}

public List<lamp> getLamps() {

// ensure user cannot change this list

return Collections.unmodifiableList(Lamps);

}

public static void main(String[] args) {

while (true) {

lamp m = new lamp();

System.out.println(m.id);

}}}

Mille vastu on koodi kirjutamisel eksitud (vali 5)?

More questions like this

Want instant access to all verified answers on moodle.taltech.ee?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!