Prev Next

Java / Methods

How to call a default method of an interface in a class?

Use super keyword along with interface name to invoke a default method.

public interface Animal {
    default void feed() {
        System.out.println("Feed some food to animals");
    }
}

public class Dog  implements Animal{
    public void feed() {
        Animal.super.feed();
    }
}

It's right time to invest in Cryptocurrencies Dogecoin! Earn free bitcoins up to $250 now by signing up.

Earn bitcoins upto $250 (free), invest in other Cryptocurrencies when you signup with blockfi. Use the referral link: Signup now and earn!

Using BlockFi, don't just buy crypto - start earning on it. Open an interest account with up to 8.6% APY, trade currencies, or borrow money without selling your assets.


Join CoinBase! We'll both receive $10 in free Bitcoin when they buy or sell their first $100 on Coinbase! Available in India also. Use the referral Join coinbase!


Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

Is the main() method required for all java classes? Can a main method be declared final? Difference between arguments and parameters in Java. What is the return type of main() method? Why does the main() method declared static? What is the the argument for main() method? Can a main() method be overloaded? When no command line arguments are passed, does the String array parameter of main() method be null? Can we invoke a static method on a null object reference in Java? Explain the Default method for interfaces in Java 8. Advantages of default method in Interface feature in Java 8. Explain the static interface methods feature in Java 8. Advantages of using static interface method in Java 8. Difference between default and static methods in Java interface. Explain pass by reference and pass by value in Java? Difference between System.exit(0), exit (1) and exit(-1) in Java. What is virtual function/method in Java? Can we define a static method in a Java interface? What is fluent interface in Java? Explain method chaining in Java. What is synthetic method in Java? What is bridge method in Java? What is a method reference in Java 8? Types of method references in Java 8. Are Java static calls less expensive than non-static calls? What is lambda expression in Java 8? What is the target type of lambda expression? Can you Serialize lamda expression in Java8? What is System.out::println expression? Other names for default methods in Java 8. Is abstract modifier allowed in default method? What is the scope of default methods in Java8? How do I extend Interfaces that contain Default Methods? Explain the scenario how Default Method can cause Multiple Inheritance Ambiguity Problem. Why Java doesn't allow overriding of static methods? Explain public static void main(String args[]) method signature. How to call a default method of an interface in a class? How to invoke a static method of an interface? Explain System.out.println().
Show more question and Answers...

Data types

Comments & Discussions