Posts

Showing posts with the label polymorphism

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

Polymorphism Interview questions

Image
 1.Can we achieve method overloading by changing the return type of method only? Ans:- in java method overloading is not possible by changing the return type of the method only because of ambiguity. 2.Can we overload java main() method()? Ans:- yes ,we can have any number of main method overloading .this is because JVM always calls main() method which receives string arrays as arguments only. program 1 program 3 program 2

Polymorphism program

Image
Polymorphism theory          Polymorphism Error Program Polymorphism interview Question  Compile time polymorphism program                                METHOD OVERLOADING  1:-                        No of Arg    (  Method overloading  ) class Demo  {       void show (int a)      {                     System . out . println ( "Method 1  " +a);      }             void show (int a,int b)      {           System . out . println ( "method 2  "  +a+ " " + b);      }     public static void main ( String arg []){             Demo   obj = new De...