logo Practice-It logo

FooBarBaz

Author: Robert Baxter (on 2021/04/02)

Consider the following classes:

        public class Foo {
            public void method1() {
                System.out.println("foo 1");
            }
        }

        public class Bar extends Foo {
            public void method1() {
                System.out.println("bar 1");
                super.method1();
                method2();
            }
        
            public void method2() {
                System.out.println("bar 2");
            }
        }
        
        public class Baz extends Bar {
            public void method2() {
                System.out.println("baz 2");
            }
        }

Suppose the following variables are defined:

        Bar var1 = new Baz();
        Object var2 = new Bar();

Indicate on each line below the output produced by each statement shown. If the statement produces more than one line of output indicate the line breaks with slashes as in a/b/c to indicate three lines of output with a followed by b followed by c. If the statement causes an error, write either runtime error or compiler error to indicate this.

var1.method1();
((Baz)var2).method2();
((Bar)var2).method2();

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.