From 28fd613fc14a83bcc7050a03483f660cc76f8f07 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Fri, 26 Oct 2018 18:20:32 -0500 Subject: [PATCH] added tracing cheat --- tracing/TestFruits.java | 116 ++++++++++++++++++++++++++++++++++++++++ tracing/out.txt | 25 +++++++++ 2 files changed, 141 insertions(+) create mode 100644 tracing/TestFruits.java create mode 100644 tracing/out.txt diff --git a/tracing/TestFruits.java b/tracing/TestFruits.java new file mode 100644 index 0000000..dcb1ac5 --- /dev/null +++ b/tracing/TestFruits.java @@ -0,0 +1,116 @@ +public class TestFruits +{ + public static void main(String[] args) + { + Apple a = new Apple(2); + System.out.println(Apple.count); + System.out.println(); + + Fruit[] fr = new Fruit[3]; + fr[0] = a; + fr[1] = new RedDelicious(); + fr[2] = new Fruit(4); + System.out.println(); + + System.out.println("Using array fr: "); + for(int i = 0; i < fr.length; i++) + { + fr[i].display(); + System.out.println(Apple.count); + System.out.println(); + } + } +} + +class Fruit +{ + public int f; + + public Fruit(int f) + { + System.out.println("Fruit"); + this.f = f; + } + + public int getF() + { + return this.f; + } + + public void f1() + { + System.out.println("FRUIT f1"); + } + + public void f2() + { + f1(); + System.out.println("FRUIT f2"); + } + + public void display() + { + System.out.println("display method from Fruit invoked"); + f2(); + } +} + +class Apple extends Fruit +{ + public static int count = 0; + + public Apple(int a) + { + super(a); + System.out.println("Apple"); + count = count + getF(); + } + + public void f1() + { + System.out.println("Apple f1"); + } + + public void f2() + { + f1(); + System.out.println("Apple f2"); + super.f1(); + } + + public void display() + { + System.out.println("display method from Apple invoked"); + f2(); + } +} + +class RedDelicious extends Apple +{ + public static int count; + + public RedDelicious() + { + super(3); + System.out.println("RedDelicious"); + count = count + getF(); + } + + public void f1() + { + System.out.println("RedDelicious f1"); + } + + public void f2() + { + f1(); + System.out.println("RedDelicious f2"); + super.f1(); + } + + public void display() + { + System.out.println("display method from RedDelicious invoked"); + f1(); + } +} diff --git a/tracing/out.txt b/tracing/out.txt new file mode 100644 index 0000000..3c66626 --- /dev/null +++ b/tracing/out.txt @@ -0,0 +1,25 @@ +Fruit +Apple +2 + +Fruit +Apple +RedDelicious +Fruit + +Using array fr: +display method from Apple invoked +Apple f1 +Apple f2 +FRUIT f1 +5 + +display method from RedDelicious invoked +RedDelicious f1 +5 + +display method from Fruit invoked +FRUIT f1 +FRUIT f2 +5 +