SuperOverride.java public class sSuperoverride { public void methodone ( ( System.out.printin("methodone from superclass."); protected void methodTwo () { System.out.println ("methodTwo from superclass."); public void methodThree () { System.out.println ("methodThree from superclass."); Suboverride.java 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.printin("methodTwo from subclass."); /*Lhis 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.");

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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

SuperOverride.java
public class Superoverride {
public void methodone () {
System.out.println("methodone from superclass.");
protected void methodTwo () {
System.out.println ("methodTwo from superclass.");
public void methodThree () {
System.out.println ("methodThree from superclass.");
Suboverride.java
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.printin ("methodTwo from subclass."):
/*Chis 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.println ("methodThree from subclass.");
Transcribed Image Text:SuperOverride.java public class Superoverride { public void methodone () { System.out.println("methodone from superclass."); protected void methodTwo () { System.out.println ("methodTwo from superclass."); public void methodThree () { System.out.println ("methodThree from superclass."); Suboverride.java 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.printin ("methodTwo from subclass."): /*Chis 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.println ("methodThree from subclass.");
(using classes SuperOverride & SubOverride)
public class TestInstanceOf {
public static String instanceName (Object o) {
if (o instanceof Suboverride)
return "Sub";
else
if (o instanceof Superoverride)
return "Super";
else
return "Something Else";
}
public static void main(String[] args) {
Object o = new Superoverride();
System.out.println(instanceName (o));
O = new Suboverride();
System.out.println(instanceName (o));
O = new Object();
System.out.println(instanceName (o));
// prints "Super".
// prints "Sub".
// prints "Something
Else".
}
}
Transcribed Image Text:(using classes SuperOverride & SubOverride) public class TestInstanceOf { public static String instanceName (Object o) { if (o instanceof Suboverride) return "Sub"; else if (o instanceof Superoverride) return "Super"; else return "Something Else"; } public static void main(String[] args) { Object o = new Superoverride(); System.out.println(instanceName (o)); O = new Suboverride(); System.out.println(instanceName (o)); O = new Object(); System.out.println(instanceName (o)); // prints "Super". // prints "Sub". // prints "Something Else". } }
Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY