(using classes SuperOverride & SubOverride) public class TestMethod { public static void main(String[] args) { Superoverride sp; sp = new SuperOverride () ; sp.methodTwo (); // calls superclass methodTwo ().. sp = new Suboverride (); sp.methodTwo (); // calls subclass methodTwo () .. note that the // same object variable (sp) is used in both // calls, with different results. The instanceof operator can be used to determine whether or not the current object reference held by an object variable is of a particular class type.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 16RQ
icon
Related questions
Question

Please encode these classes and run them for inspection/analysis/scrutiny.

TestMethod.java
(using classes SuperOverride & SubOverride)
public class TestMethod {
public static void main (String[] args) {
superoverride sp;
sp = new Superoverride ();
sp.methodTwo () ; // calls superclass methodTwo ()...
sp = new Suboverride ();
sp.methodTwo () ; // calls subclass methodTwo (). note that the
// same object variable (sp) is used in both
// calls, with different results.
The instanceof operator can be used to determine whether or not the current object reference held
by an object variable is of a particular class type.
Transcribed Image Text:TestMethod.java (using classes SuperOverride & SubOverride) public class TestMethod { public static void main (String[] args) { superoverride sp; sp = new Superoverride (); sp.methodTwo () ; // calls superclass methodTwo ()... sp = new Suboverride (); sp.methodTwo () ; // calls subclass methodTwo (). note that the // same object variable (sp) is used in both // calls, with different results. The instanceof operator can be used to determine whether or not the current object reference held by an object variable is of a particular class type.
SuperOverride.java
public class Superoverride {
public void methodone () {
System.out.println ("methodone from superclass.");
protected vaid methodTwo () {
System.out.println ("methodTwo from superclass.");
public void methodThree () {
System.out.println ("methodThree from superclass.") ;
Suboverride.java
6.
public class suboverride extends Superoverride {
public void methodTwo () ( /*this overrides methodTwo () of the superclass.
note that this is less restrictive
(public here vis-à -vis protected in the superclass).*/
System.out.println ("methodTwo from subclass.");
/*this will be invalid, since the accessibility of the overriding
method is more restrictive (i.e., from public to private).*/
// private void methodone () (}
public void methodThree (int i) { /*this method is overloaded across classes. */
System.out.printin ("methodThree from subclass.");
Transcribed Image Text:SuperOverride.java public class Superoverride { public void methodone () { System.out.println ("methodone from superclass."); protected vaid methodTwo () { System.out.println ("methodTwo from superclass."); public void methodThree () { System.out.println ("methodThree from superclass.") ; Suboverride.java 6. public class suboverride extends Superoverride { public void methodTwo () ( /*this overrides methodTwo () of the superclass. note that this is less restrictive (public here vis-à -vis protected in the superclass).*/ System.out.println ("methodTwo from subclass."); /*this will be invalid, since the accessibility of the overriding method is more restrictive (i.e., from public to private).*/ // private void methodone () (} public void methodThree (int i) { /*this method is overloaded across classes. */ System.out.printin ("methodThree from subclass.");
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT