(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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education