Jump to content
  • 0

[Question] About How Works Inheritance Method.


Question

Posted (edited)


//main class

public class Devs {

 

public static void main (String[]args) {

 

Tryskel dTryskel=new Tryskel ();

Wyatt dWayatt=new Wyatt():

 

}

}

 

//1st class

public class Tryskel {

 

public boolean L2jdeveloper=true;

public boolean Professional=true;

public boolean Clever=true;

public boolean Kind=true;

public boolean Cool=true;

 

}

//2nd class

 

public class Wyatt {

 

public boolean L2jdeveloper=true;

public boolean Professional=true;

public boolean Creative=true;

public boolean Strict=true;

public boolean Tall=false; //making joke

 

 

 

 

 

 

 

}

 

//3rd class

 

public class Me extends Wyatt {

 

 

 

// SO everything i wrote here and declaration of Wyatt will be applied to me ?

 

//am i right?

 

 

 

 

 

}

 

 

 

 

Edited by andon19

2 answers to this question

Recommended Posts

  • 0
Posted (edited)

You can reuse any boolean of Wyatt in Me. Adding your own variables in Me are only shared amongst classes extending Me, or Me itself.

 

On a L2J base :

 

L2PcInstance extends L2Playable which extends itself L2Character. Meaning a L2PcInstance can reuse stuff from L2Character.

L2PetInstance extends L2Summon which extends L2Playable which extends L2Character.

 

As you can see the relation between players and summons stop at L2Playable, meaning whatever you edit at and before L2Playable can affect both.

 

On another note, you can override methods content with @override. Overriden methods means you "re-write" content of the method to fit with your class.

 

To take an example, isAutoAttackable() is overriden following cases : returning always true for L2Character, but not always true for summons and players.

 

So if you don't rewrite anything it will fully inherit, but you can give exceptions to that previous statement using override.

 

Hope it's clear. If it's not, consider to use a paper and a pencil and draw a tree. I give you the beginning :

 

 

L2Pet    L2Servitor

   |         |

L2Summon           L2PcInstance

     |                             |

     ------  L2Playable ---------

                    |

                   ...

 

Edited by Tryskell
  • 0
Posted (edited)

Everything that u had advised me, u and wyatt i keep it on my l2j notes.THANK YOU once more :) i appreciate ur help

Edited by andon19
Guest
This topic is now closed to further replies.


×
×
  • Create New...