by Dinesh Thakur

 

          import java.io.*;

          class ScienceStudent
              {
                    int r,p,c;
                    String n,s;
                    BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
                    ScienceStudent()
                    throws IOException
                      {
                         System.out.println("Enter Roll Number : ");
                         s=bf.readLine();
                         r=Integer.parseInt(s);
                         System.out.println("Enter Name of Student : ");
                          n=bf.readLine();
                      }
                         void getSubject()
                         throws IOException
                        {
                            System.out.println("Enter Physics Marks :");
                            s=bf.readLine();
                            p=Integer.parseInt(s);
                            System.out.println("Enter Chemistry Marks :");
                            s=bf.readLine();
                            c=Integer.parseInt(s);
                        }
                            void StudentDetail()
                              {
                                  System.out.println("Roll :"+ r);
                                  System.out.println("Name : "+n);
                              }
                                  void StudentSubject()  
                                    {
                                        System.out.println("Physics : "+p);
                                        System.out.println("Chemistry : "+c);
                                    }
              }
                   class arts extends ScienceStudent
                       {
                           int his,geo;
                           arts() throws IOException
                              {
                                  super();
                              }
                                  void getSubject()
                                  throws IOException
                                      {
                                           BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
                                           String s;
                                           System.out.println("Enter History Marks ");
                                           s=bf.readLine();
                                           his=Integer.parseInt(s);
                                           System.out.println("Enter Geography Marks ");
                                           s=bf.readLine();
                                           geo=Integer.parseInt(s);
                                           geo=Integer.parseInt(s);
                                           geo=Integer.parseInt(s);
                                      }
                                            void StudentSubject()
                                              {
                                              System.out.println("History :"+ his);
                                                  System.out.println("Geograhy  :"+geo);
                                          };
                       }
                             class ExampleOverloading
                                  {
                                      public static void main(String args[])
                                         {
                                             System.out.println("Enter Details of Science Student :");
                                              try
                                                {
                                                    ScienceStudent sc=new ScienceStudent();
                                                    sc.getSubject();
                                                    System.out.println("Enter Details of Arts Student :");
                                                    arts ar=new arts();
                                                    ar.getSubject();
                                                    System.out.println("The Details of Science Student is :");
                                                    sc.StudentDetail();
                                                    sc.StudentSubject();
                                                    System.out.println("The Details of Arts Student is :");
                                                    ar.StudentDetail();
                                                    ar.StudentSubject();
                                                }
                                                    catch(IOException e){}
                                         }
                                  };

Example of Method Overloading in Java