Sunday, 14 June 2020

Accessing interface variables in Java

you can use interfaces to import shared data constants into multiple classes by simply declaring an interface that contains variables that are initialized to the desired values. They are accessed as

syntax: interfaceName.variablename;

interface Father
{
float HT=6.2F;
void height();
}
interface Mother
{
float HT=5.8F;
void height();
}
class child implements Father, Mother
{
  void height()
{
  float cht=(Father.HT+Mother.HT)/2;
  System.out.println(“child height=”+cht);
}
}
class AccessDemo
{
public static void mian(String args[])
{

    child ch=new child();
       ch.height();
}
}



0 comments:

Post a comment

Find Us On Facebook

Contact Us

Name

Email *

Message *

C Programming

More

C++ Tutorial

More

Java Tutorial

More

software engineering

More

MS Office

More

Database Management

More

Advertisement

Top