I am fairly new to Java and I am writing a program that has two child classes using the same parent method, and I wanted to make a way to track which one calls the method.
Example:
public class Parent(){
public static int ChildOneUses, ChildTwoUses;
public void Example(){
/* code */
if(/*ChildOne called the method*/)
ChildOneUses++;
else if(/*ChildTwo called the method*/)
ChildTwoUses++;
}
}
public class ChildOne extends Parent(){
/* code */
}
public class ChildTwo extends Parent(){
/* code */
}
public static void main(String[] args){
ChildOne ChildOne = new ChildOne();
ChildTwo ChildTwo = new ChildTwo();
ChildOne.Example();
ChildTwo.Example();
ChildTwo.Example();
}
/* If this code were to run, ChildOneUses would equal 1 and ChildTwoUses would equal 2 */
I am not sure that this question even has an answer other than just moving the parent method to each of the child classes to track them on their own.