« first day (30 days earlier)
← previous day
last day (14 days later) »
Skizo
18:04
@DeveloperXY Yo are you there?
I have a Java question to ask you @DeveloperXY
DeveloperXY
18:20
heey
Skizo
hey bro
DeveloperXY
How are you doing ? It has been a long time..
Skizo
Ya bro :(
You forgot me
I have a question...
Maybe it's a noob one
It's about Java
Ready to get that?
DeveloperXY
go ahead
Skizo
I've created an Abstract class okay? And on it I have 1 constructor
DeveloperXY
18:23
ya
Skizo
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
DeveloperXY
They should be accessible directly
aren't they ?
Skizo
Nope
DeveloperXY
Can you show me a picture of your code ? From the IDE ?
Skizo
I put on my other class( on super of my constructor ) for example Hello
and it says "it should be static"
._.
DeveloperXY
18:26
I need a picture
Skizo
ok
do you have TeamViewer?
DeveloperXY
no
Skizo
ok wait
I'm running Eclipse
DeveloperXY
Let me guess
your main method is contained within one of those 2 classes ?
Skizo
what method
See
gyazo.com/6f3b9d434cb29e62350425d18bd35157
gyazo.com/1d4797f2c51109da372f677045d4c7a1
Where I've put the 1
I want to put Verd
or something
DeveloperXY
18:36
Ah I see
You can't do that
Skizo
why not bro
DeveloperXY
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
Skizo
yep
DeveloperXY
which means that it's value won't change
anywhere else in your code right ?
Skizo
yes
the teacher said
Each subclass inform the superclass their color. Not a constructor parameter
DeveloperXY
18:43
& did he say that those values had to be
final
?
Skizo
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 ._.
DeveloperXY
want the quick fix ?
Skizo
the quick fix
is putting it static
DeveloperXY
Make them
static final
Skizo
and it will work I tested it
DeveloperXY
18:45
yeah
Skizo
if I remove the final
will it work?
DeveloperXY
final
has nothing to do with it
Skizo
nope it doesn't
DeveloperXY
Consider this example:
2 classes,
A
and
B
A
is
abstract
, &
B extends A
you with me ?
Skizo
yes
DeveloperXY
18:48
The class
A
has 1 attribute
public final int verd = 0
Skizo
aight
DeveloperXY
now to make this easier for you
consider that the constructors of these 2 classes
contribute
to the
construction
of a
B
instance
like
Skizo
yap
DeveloperXY
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 ?
Skizo
yes
that's right
DeveloperXY
18:54
do you know about the implicit call to
super()
in a subclass ?
Skizo
well to call the constructor
of the superclass, right?
DeveloperXY
nope, the implicit one
okey look
when instantiating a
B
object
Skizo
y
DeveloperXY
1- the constructor of
A
is called
2- The constructor of
A
contributes with its 50% share
Skizo
why 50%
DeveloperXY
19:02
we said
A
gives 50 &
B
gives 50 remember ?
Skizo
yep
DeveloperXY
that's the fifty I'm talking about
Skizo
I got it
DeveloperXY
now the constructor of
B
contributes with the last 50%
& the object is now complete
Skizo
yap
DeveloperXY
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 ?
Skizo
yes
you do...
now I got it..
DeveloperXY
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
Skizo
ya, then I can call
this static int...
I got it now
thanks teacher :P
DeveloperXY
You're welcome
« first day (30 days earlier)
← previous day
last day (14 days later) »
all rooms
Transcript for
Feb
10
Feb '16
18
Mar
3
♦
Room for Skizo and Mohammed Aouf ZOUAG
join this room
about this room
00:00
06:00
12:00
18:00
all times are UTC
site design / logo © 2024 Stack Exchange Inc;
legal
mobile