J2EEOnline J2EE  

Java Packages and Interfaces  «Prev 
Ambiguous Interface Fields with Exceptions
What will be the output of compiling and running the following program:
package com.java.inheritance;
date_created: February 6, 2015	/	
date_updated: July 1, 2015
[01 - Java Class Design ] (Overriding/ Overloading) 
import java.io.IOException;
import java.sql.SQLException;

interface I1 { void m1(String str1) throws IOException;}
interface I2 { void m1(String str2) throws SQLException; }

public class TestClass implements I1, I2 {
 public static void main(String args[]) throws Exception {
  TestClass tc = new TestClass();
   I1 i1 = (I1) tc; // This is valid.
   i1.m1("i1 reference variable");
   I2 i2 = (I2) tc; // This is valid too.
   i2.m1("i2 reference variable");
 public void m1(String s1) {
  System.out.println("In m1(): s1= " + s1);
Program Output 
In m1(): s1= i1 reference variable
In m1(): s1= i2 reference variable

Ambiguous Interface Fields

Having ambiguous fields does not cause any problems but referring to such fields in an ambiguous way will cause a compile time error.