Day9 Polymorphism
Day9 Polymorphism
A public
B protected
C private
D Default
Q2. Which is the superclass of wrapper classes like Boolean and Character?
A Number
B Wrapper
C Object
D Math
• One thing can exhibits more than one form is called polymorphism.
• Polymorphism is a Greek word poly means many and morphism means forms.
• Polymorphism shows same functionality(method name same) with different logics
execution.
• It allows the same name for a member or method in a class with different types.
● Code Reusability
● Reduces coupling
• Method overloading
explicitly by the programmer
• Constructor overloading
If class has more than one constructors, then they are called as overloaded
constructors. When constructors are overloaded, they must differ in
● Number of parameters
● Type of parameters
● Order of parameters
● In a class hierarchy, when a method in a subclass has the same name and type
signature as a method in its super class, then the subclass method overrides
the super class method
• While overriding child class method signature & parent class method signatures must
be same otherwise we are getting compilation error.
• The return types of overridden method & overriding method must be same.
• Static methods are bounded with class hence we are unable to override static
methods.
The execution period for the Compile-Time The execution period for the Run-Time
Polymorphism is less Polymorphism is more
Integrating the right method call with the Combining the correct method call with the
proper method is done in compile-time right method is done in run-time
A final
B private
C Override
D @Override
Q2. Which method signature in Java allows you to override a superclass method
while changing the return type?
Consider doing an extra feature for the stage show organizers. Bring up an interactive
console application for Billing so that our application looks unique from other competitors.
Customers pay using cash, online wallets, and credit card. For each category obtain the
necessary information from the user. You also require a receipt for all the transactions
which should be printed at the end of the transaction. Let's increase our coding proficiency
by implementing Function overloading for the payments. Hence write a program meeting all
the above specifications.
Create a driver class called Main. In the Main method, obtain input from the user in CSV
format and call appropriate methods for transactions. If a choice other than specified is
chosen, print "Invalid choice".
Note: display one digit after the decimal point for double values.
All class names, attribute names, and method names should be the same as specified in
the problem statement.]
The next integer value is Payment mode. If 1. Cash payment, 2.Wallet payment and
3.Credit card payment.
If the Payment mode is 1, then read the integer input which represents the amount
If the Payment mode is 2, then read integer input which represents the amount, followed by
the wallet number(string)
If the Payment mode is 3, then read string input which represents the cardholder name,
followed by the amount (integer), credit card type(string), and CCV number(String)
Output Format
TNS India Foundation | ‹#›
Partners in Economic Transformation
Refer to the sample Output for formatting.
Sample Input and Output:
Magic show,Lunu,43 Stage event:Magic show
1 Customer:Lunu
500 Number of seats:43
Amount 500.0 paid in cash
PCB workshop,Ahamed,3 Stage event:PCB workshop
2 Customer:Ahamed
300 Number of seats:3
ASD-951 Amount 300.0 paid using wallet
number ASD-951
Electronics,Raja,2 Stage event:Electronics
3 Customer:Raja
Raja Number of seats:2
200 Holder name:Raja
Master Amount 200.0 paid using Master
9874-4758-9856 card
CCV:9874-4758-9856
Foodies,Alice,1
TNS India Foundation | ‹#›
Partners in Economic Transformation
Invalid choice
Let’s Reflect -