I want to execute the defined body of a default method in interface by creating an object of concrete implementation class which has also overridden the method. Whether I create the object of concrete implementation class directly or whether through dynamic binding/polymorphism , the body defined/ overriden in the implementation class is only getting executed. Please see the below code
interface Banking
{
void openAc();
default void loan()
{
System.out.println("inside interface Banking -- loan()");
}
}
class Cust1 implements Banking
{
public void openAc()
{
System.out.println("customer 1 opened an account");
}
public void loan()
{
// super.loan(); unable to execute the default method of interface
//when overridden in implementation class
System.out.println("Customer1 takes loan");
}
}//Cust1 concrete implementation class
class IntfProg8
{
public static void main(String[] args)
{
System.out.println("Object type=Banking \t\t\t Reference type=Cust1");
Banking banking = new Cust1();
banking.openAc();
banking.loan();
}
}
I want to know how to print the following in console inside interface Banking -- loan()
when the default method is overridden