I have to create class definiton which could approve argument that the object has already existed at the moment when constructor was inducted.
I have no idea how to explain this, I’ve tried somethin like this but it’s propably wrong:
public class B {
int obj;
public B() {
}
public static void main(String[] args) {
B object = new B();
System.out.println(object)
}
}
Code which i wrote, from the first excercise is:
public class Bulb {
static int a;
public Bulb(int ab) {
a = ab;
}
public static void main(String[] args) {
Bulb object = new Bulb(a);
System.out.println(object);
}
And it’s with one parameter constructor.
After our long comment thread, it sounds like we’ve determined that what you’re doing is learning about inheritance and polymorphsim. The B class you specified has to inherit from Bulb, and you must prove that Bulb’s constructor is invoked first BEFORE B’s constructor. I’m not certain if there’s any better way than to use log outputs. Your code nearly has everything you need, except for the extension, and logger messages. You can do both like so:
And in the B class, which extends Bulb:
Does that make sense?
Edit:
I forgot to mention: In Java, when you have an inheritance structure, the constructors are always called from top to bottom. Meaning, the top most class in your hierarchy is called first (in this case, that would be Bulb), and trickles down to the bottom (your B class, for example).