0

question about overriding methods

So basically i created a class called "Skills" with a field double skilldamage..and created 3 methods with following names Skill1 ,Skill2 Ultimate.. each of methods return a amount of Skilldamage and a Text Messeage.. so is there any way to override these methods inside Skills class without using inheritance.. I want to use this class as a field in a Hero class so it can inherit this skills .. code: public class Skills { private double Skilldamage; public double Skill1(double SkillDamage) { System.out.println("Dummy Skill"); this.Skilldamage = SkillDamage; return SkillDamage; } public double Skill2(double SkillDamage) { System.out.println("Dummy Skill 2"); this.Skilldamage = SkillDamage; return SkillDamage; } public double Ulimate(double SkillDamage) { System.out.println("Ultimate Skill"); return SkillDamage; } }

23rd Jul 2020, 1:39 PM
Alapottra Chakma
Alapottra Chakma - avatar
5 Answers
+ 1
Use the @override annotation (and avoid to answer to your post before there was an answer, I almost missed you because 1 answer -> already answered ;-).
23rd Jul 2020, 1:52 PM
Sandra Meyer
Sandra Meyer - avatar
0
ps: My point is to have a indiviual hero that inherits from a "Hero" Class and that hero class should have that Skills as a field.. so i can modify each indivual hero's skills and stuff
23rd Jul 2020, 1:42 PM
Alapottra Chakma
Alapottra Chakma - avatar
0
If am understood correctly, Just use skills class object in hero class. Then use methods by object. No inheritance need.
23rd Jul 2020, 1:55 PM
Jayakrishna 🇼🇳
0
@Sandra does @override method works without inheriting the class like without using extend thing.. ? Im using this as a field
23rd Jul 2020, 1:57 PM
Alapottra Chakma
Alapottra Chakma - avatar
0
No, @override is especially for "over-writing" a method (body) from parent. If you don't inherit anything, there is no need to override.
23rd Jul 2020, 1:59 PM
Sandra Meyer
Sandra Meyer - avatar