Maruthi Krishna has Published 951 Articles

How to override only few methods of interface in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 11:10:33

6K+ Views

Once you implement an interface from a concrete class you need to provide implementation to all its methods. If you try to skip implementing methods of an interface at compile time an error would be generated.Example Live Demointerface MyInterface{    public void sample();    public void display(); } public class InterfaceExample ... Read More

Can we overload methods of an interface in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 11:04:47

6K+ Views

Polymorphism is the ability of an object to perform different actions (or, exhibit different behaviors) based on the context.Overloading is one of the mechanisms to achieve polymorphism where a class contains two methods with the same name and different parameters.Whenever you call this method the method body will be bound ... Read More

What happens if we overload default methods of an interface in java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 10:59:13

1K+ Views

An interface in Java is similar to a class but, it contains only abstract methods and fields which are final and static.Since Java8 static methods and default methods are introduced in interfaces.Default methods − Unlike other abstract methods these are the methods that can have a default implementation. If you ... Read More

How to hide unsupported interface methods from class in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 10:49:39

812 Views

Actually you can’t, once you implement an interface it is a must to provide implementation to all its methods or, make the class abstract. There is no way to skip methods of an interface without implementing (unless they are default methods). Still, if you try to skip implementing methods of ... Read More

Can we change the access specifier from (public) while implementing methods from interface in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 10:43:28

503 Views

An interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a type should be you can define an interface.To create an object of this type you need to implement this interface, provide ... Read More

Can we synchronize abstract methods in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 10:36:50

680 Views

An abstract method is the one that does not have a body. It contains only a method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();To use an abstract method, you need to inherit it by extending its class and provide implementation (body) to it. If ... Read More

How abstraction is achieved using interfaces in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 10:28:50

7K+ Views

Abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to the user. In other words, the user will have the information on what the object does instead of how it does it.Since all the methods of the interface are abstract and ... Read More

Bounded-types in generics in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 09-Sep-2019 09:03:42

7K+ Views

Whenever you want to restrict the type parameter to subtypes of a particular class you can use the bounded type parameter. If you just specify a type (class) as bounded parameter, only sub types of that particular class are accepted by the current generic class. These are known as bounded-types ... Read More

How can we restrict Generics (type parameter) to sub classes of a particular class in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 09-Sep-2019 08:56:43

2K+ Views

Whenever you want to restrict the type parameter to subtypes of a particular class you can use the bounded type parameter. If you just specify a type (class) as bounded parameter, only sub types of that particular class are accepted by the current generic class.You can declare a bound parameter ... Read More

Can we have generic constructors in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 09-Sep-2019 08:43:58

2K+ Views

Generics is a concept in Java where you can enable a class, interface and, method, accept all (reference) types as parameters. In other words it is the concept which enables the users to choose the reference type that a method, constructor of a class accepts, dynamically. By defining a class ... Read More

Advertisements