Question
Suggest another way to take advantage of the dynamic binding in that code. Write the main method to demonstrate the correct functionality of the additions/modifications:
Suggest another way to take advantage of the dynamic binding in that code. Write the main method to demonstrate the correct functionality of the additions/modifications:
************************************
import java.util.*;
class Wk6EllicottG{ public static class Customer{ Scanner userInput = new Scanner(System.in);
//Attributes String name;
//constructor Customer(){ System.out.println("Please enter name: "); name = userInput.nextLine();
}
private void sayHi(){ System.out.println("Hi, " + name + ", I'm the parent class!"); sayHi(); }
public static class Hero extends Customer {
//Attributes
//Constructor Hero(){ sayHi(); }
//override private void sayHi(){ System.out.println("Hi, " + name + ", I'm the Hero class!"); }
} void join(){ Hero newHero = new Hero(); sayHi(); }
}//end customer class
public static void main(String[] args){ Customer test = new Customer.Hero(); //dynamic binding } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started