CS203
Spring 2013
Apr 5
cs203 course directory
Examples rather than the default
tester.jar file to your project’s Libraries
A class and a B class to your project, and copy/paste the respective code below: /** * cs203 * Spring 2013 * Lab 9 * * file: B.java */ public class B { public void bmethod1() { System.out.println("class B: bmethod1() called..."); } public void bmethod2() { System.out.println("class B: bmethod2() called, calling which class's bmethod1?..."); bmethod1(); } } /** * cs203 * Spring 2013 * Lab 9 * * file: A.java */ public class A extends B { @Override public void bmethod1() { System.out.println("class A: bmethod1() called..."); } }
main() method in your Examples class to experiment with classes A and B. Your code should generate the following output when run:
run:
Initializing myB, an object of type B, to an instance of type B...
class B: bmethod1() called...
class B: bmethod2() called, which class's bmethod1() will I call???
class B: bmethod1() called...
Initializing myB, and object of type B, to an instance of type A...
class A: bmethod1() called...
class B: bmethod2() called, which class's bmethod1() will I call???
class A: bmethod1() called...
BUILD SUCCESSFUL (total time: 0 seconds)
bmethod1.
public final class B {
Make class B final and observe what happens when you try to compile your code. Discuss with Marc or one of our coaches.
submit203 lab9 lab9