What is the interface ?

No comments

C++  supports  multiple   inheritance  implementations  but  in  jaba  does  not  supports  this.  Java  provides  and  an  alternative  approach  known  as  interface  to  supports  the  concept  of  multiple  inheritance.

           Although  a  jav  class  can’t  be  of  more  than  supper  class  it  can  implement  more  than  one  interface.  There  by  enablinar  we  to  create  classes  that  built  upon  other  classes  without  the  problems  created  by  multiple  inheritance . 

The  syntax  will  be :


Interface  interfacename
{                    variable  declaration;
                     Method  declaration;
                    }
Class  student
{               int  rollNumber;
                Void  getNumber(int  n)
               {    rollNumber=n;
                }
void  putNUmber()
{  system.out.println(“Roll  No:”+  rollNumber);
         }
class   Text  extends  student
{      float  part1, part2;
          Void  getMarks(float  m1,  float  m2)
          {    part1=m1;
               Part2=m2;
          }
Void  putMarks()
{  system.out.println(“Marks  obtained”);
  System.out.println(“Part1=”+part1);
  System.out.println(“Part2=”+part2);
            }
}
Interface  sports
{              float  sportWt=6.oF;
                Void  putWt();
        }
Class  Results  extends  Test  implements  sports
{         float   total;
          Public  void  putWt()
           {
System.out.println(“Sports Wt=”+sports  Wt);
}
Void  display()
{  total =part1+part2+sportWt;
Put  Number();
Put  Marks();
PutWt();
System.out.println(“Total  score=”+  total);
                }
}
Class  Hybrid
{      public  static  void  main(String obj[])
         Results   student1=new  Results();
Student1.getNumber(1234);
Student1.getMarks(27.5F,  33.0F);
Student  display();
       }
}

No comments :

Post a Comment

Subscribe

Milan Panda
Admin
About Me | Contact
Copyright 2023-2024 © Programming1011 . 🎀 Developed and Design By- Milan Panda. Happy Holi All Of You 🎀