« first day (30 days earlier)    last day (14 days later) » 

18:04
@DeveloperXY Yo are you there?
I have a Java question to ask you @DeveloperXY
18:20
heey
hey bro
How are you doing ? It has been a long time..
Ya bro :(
You forgot me
I have a question...
Maybe it's a noob one
It's about Java
Ready to get that?
go ahead
I've created an Abstract class okay? And on it I have 1 constructor
18:23
ya
On my other class is like : public class DeveloperXY extends GOD (that's the abstract class<--)
on my abstract class
I have 4 public variables
like : public int Hello = 1; public int Hwllo = 2; etc...
How do I call those variables on my Abstract class?
sorry not on my Abstract class I mean on DeveloperXY class
They should be accessible directly
aren't they ?
Nope
Can you show me a picture of your code ? From the IDE ?
I put on my other class( on super of my constructor ) for example Hello
and it says "it should be static"
._.
18:26
I need a picture
ok
do you have TeamViewer?
ok wait
I'm running Eclipse
Let me guess
your main method is contained within one of those 2 classes ?
what method
See
Where I've put the 1
I want to put Verd
or something
18:36
Ah I see
You can't do that
why not bro
because you are trying to reach an attribute that belongs to the super class inside the call to super
verd is a final member of your superclass
yep
which means that it's value won't change
anywhere else in your code right ?
yes
the teacher said
Each subclass inform the superclass their color. Not a constructor parameter
18:43
& did he say that those values had to be final ?
she said : Add five attributes constant public class for working with the color name
container instead of a numeric value
constant means final I guess ._.
want the quick fix ?
the quick fix
is putting it static
Make them static final
and it will work I tested it
18:45
yeah
if I remove the final
will it work?
final has nothing to do with it
nope it doesn't
Consider this example:
2 classes, A and B
A is abstract, & B extends A
you with me ?
yes
18:48
The class A has 1 attribute
public final int verd = 0
aight
now to make this easier for you
consider that the constructors of these 2 classes contribute to the construction of a B instance
like
yap
in order for a B object to be fully constructed
The constructor of A has to contribute with 50%, & the constructor of B with 50%
okey ?
yes
that's right
18:54
do you know about the implicit call to super() in a subclass ?
well to call the constructor
of the superclass, right?
nope, the implicit one
okey look
when instantiating a B object
1- the constructor of A is called
2- The constructor of A contributes with its 50% share
why 50%
19:02
we said A gives 50 & B gives 50 remember ?
yep
that's the fifty I'm talking about
I got it
now the constructor of B contributes with the last 50%
& the object is now complete
yap
19:04
What you were trying to do
is to access the not-constructed-yet part of the object
since verd is an instance variable
that means that it is initialized by the constructor of the class
You were trying to access verd when calling super(), which means before that A constructed its 50%
Am I making any sense ?
yes
you do...
now I got it..
but if you make it static
the 50% rule is no longer applied
since the class takes responsability for initializing it
The constructor is relieved from its duties
ya, then I can call
this static int...
I got it now
thanks teacher :P
You're welcome

« first day (30 days earlier)    last day (14 days later) »