Polymorphism Error Program

 1:-

class aman{
   
class Demo
 {
     void show () //yha pe arg de
     
         System.out.println("1  METHOD ");
     }
     void show () //or yha phale bala se different arg de to program sai ho jaye ga
     {
         System.out.println("2  METHOD");
     
     }
 public static void main(String args[])
 {
     Demo obj= new Demo();
     obj.show();
     
 }
     
 }
 C:\java>javac Testing.java
Testing.java:7: error: method show() is already defined in class Demo
         void show ()
              ^
1 error

C:\java>
Ye program error show karega kuki show name ka do method hai compile  ko pata nahi kon sa show method ko call karu 


why error same name right same class but different argument .
is program me error dik rha hai kuki
1. method same name hona cahiya wo isme hai .
2.class ek hai hona cahiya wo bhi hai
3.but arg differet hona cahiya wo nahi hai isliya ye program me error aa rha hai
                          
2:-
class Demo
 {
     void show(int a)
     {
         
         System.out.println("Method 1");
     }
     
     void show(int a,int b)
     {
         System.out.println("method 2");
     }
    public static void main(String arg[]){
       
    Demo  obj= new Demo();
    obj.show();// yha pe value difine nahi kya hai
    obj.show();// or yah pe ve
 }
 }
OUTPUT
C:\java>javac Testing.java
Testing.java:17: error: no suitable method found for show(no arguments)
        obj.show();
           ^
    method Demo.show(int) is not applicable
      (actual and formal argument lists differ in length)
    method Demo.show(int,int) is not applicable
      (actual and formal argument lists differ in length)
1 error

yha pe error aya hai ki show method me arg value difine nahi kiya hai
3:-
4:-
5:-
6:-
7:-
8:-
9:-
10:-
























































































































f                                                          

Comments