0

It's been long time since I've asked a question so forgive my mistakes.

So, I have a code which I don't understand. It's dealing with interface and super/sub class. I even have the answers to it but I just don't know how it got to the answer. My question is that, how would I learn tracing or is there a way I can see which lines are executed first in Eclipse?

For example, does eclipse or any other tool allows the user to actually see which and why the lines are printing?

Here is my code. I Have the correct answer to it but I just don't know how they traced it. Any help would be appreciated.

interface Silly {
 public void narf();
 public void poit(Silly s);
}

public class Bird implements Silly {
 public static void main(String args[]) {

 System.out.println("zero");
 Silly s = new SillyBird(1);
 Silly s2 = new Loony();
 s.poit(s2);
 s2.poit(s);
 System.out.println("zymurgy");
 }
 public Bird() {
 this(0);
 System.out.println("zircon");
 }
 public Bird(int i) {
 System.out.println("zanzibar");
 }
 public void narf() {
 System.out.println("zort");
 }
 public void poit(Silly s) {
 s.narf();
 }
}

class SillyBird extends Bird {
 public SillyBird() {
 System.out.println("duchess");
 }
 public SillyBird(int i) {
 super(i);
 }
 public void narf() {
 System.out.println("drum");
 super.narf();
 }
}

class Loony extends SillyBird {
 public Loony() {
 System.out.println("stupendous");
 }
 public void narf() {
 System.out.println("snark");
 }
}

The output of the above code was:

zero
zanzibar
zanzibar
zircon
duchess
stupendous
snark
drum
zort
zymurgy
user372204
  • 69
  • 2
  • 10
  • 1
    Are you asking about the _Eclipse_ debugger? There are many resources on the Internet regarding this, including the article [Debugging the Eclipse IDE for Java Developers](https://www.eclipse.org/community/eclipse_newsletter/2017/june/article1.php) – Abra Apr 19 '19 at 04:54
  • So would that help me trace the above code? – user372204 Apr 19 '19 at 04:56
  • I believe so. Set a breakpoint, as explained in the article, and then step through the code. – Abra Apr 19 '19 at 04:57

1 Answers1

0

As mentioned by @Abra in the comments you can set a breakpoint at the functions you want to have a look at and use the ‚go into‘ operation to see what is going on in the function at execution. The debugger will show you the state of all locals and globals at each step of the execution

RomanHDev
  • 104
  • 5