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

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top