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