
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9150 Articles for Object Oriented Programming

8K+ 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 with the method call based on the parameters.ExampleIn the following Java program, the Calculator class has two methods with name addition the only difference is that one contains 3 parameters and the other contains 2 parameters.Here, we can call the addition method by passing two integers or three integers. Based ... Read More

2K+ 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 have a default method in an interface, it is not mandatory to override (provide body) it in the classes that are already implementing this interface.In short, you can access the default methods of an interface using the objects of the implementing classes.Example Live Demointerface MyInterface{ public static int num = ... Read More

1K+ 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 an interface a compile-time error would be generated.Example Live Demointerface MyInterface{ public static int num = 100; public void sample(); public void getDetails(); public void setNumber(int num); public void setString(String data); } public class InterfaceExample implements MyInterface{ public static int num = 10000; public ... Read More

661 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 a body for all the abstract methods of the interface and obtain the object of the implementing class.All the methods of the interface are public and abstract and, we will define an interface using the interface keyword as shown below −interface MyInterface{ public void display(); public void setName(String ... Read More

977 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 a class contains at least one abstract method, you must declare it abstract.Example Live Demoimport java.io.IOException; abstract class MyClass { public abstract void display(); } public class AbstractClassExample extends MyClass{ public void display(){ System.out.println("subclass implementation of the display method"); } public static void main(String ... Read More

9K+ 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 the user doesn’t know how a method is written except the method signature/prototype. Using interfaces, you can achieve (complete) abstraction.Abstraction in interfacesAn 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 ... Read More

2K+ Views
The Java Swing allows us to customize the GUI by changing the look and feel(L&F). The look defines the general appearance of components and the feel defines their behavior. L&Fs are subclasses of the LookAndFeel class and each L&F is identified by its fully qualified class name. By default, the L&F is set to the Swing L&F ( Metal L&F)To set the L&F programmatically, we can call the method setLookAndFeel () of the UIManager class. The call to setLookAndFeel must be done before instantiating any Java Swing class, otherwise, the default Swing L&F will be loaded.Syntaxpublic static void setLookAndFeel(LookAndFeel newLookAndFeel) throws UnsupportedLookAndFeelExceptionExampleimport java.awt.*; import ... Read More

327 Views
In Java, both double and float are data types that are used to declare a variable that can store only decimal values or floating point numbers. For example: 1.2343, 3.343, 24.321234, etc. The double data type is larger in size compared to the float data type. When to Prefer Double Type Over Float Type A double-type is preferred over a float-type if a more precise and accurate result is required. The precision of double-type is up to 15 to 16 decimal points, while the precision of float type is only around 6 to 7 decimal digits. Following are the syntaxes for ... Read More

1K+ Views
This article will discuss how to check if a string ends with a specific substring, which means we need to verify whether the last part of the string matches a given sequence of characters or not. For example, if the given input string values are "Gaint", "allegiant", "applicant", "combatant", "elephant", and if the substring is "ant", the result would be true for all the given values. A String is an object that represents an immutable sequence of characters and cannot be changed once created. The java.lang.String class can be used to create a string object. There are several ways to ... Read More

7K+ Views
Yes, the protected method of a superclass can be overridden by a subclass. If the superclass method is protected, the subclass overridden method can have protected or public (but not default or private) which means the subclass overridden method can not have a weaker access specifier. Example class A { protected void protectedMethod() { System.out.println("superclass protected method"); } } class B extends A { protected void protectedMethod() { System.out.println("subclass protected method"); } } public class Test { public static void main(String args[]) { B b = new B(); b.protectedMethod(); } } Output subclass protected method