
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

1K+ Views
Whenever you inherit a superclass a copy of superclass’s members is created at the subclass and you using its object you can access the superclass members.If the superclass and the subclass have instance variable of same name, if you access it using the subclass object, the subclass field hides the superclass’s field irrespective of the types. This mechanism is known as field hiding.But, since it makes code complicated field hiding is not recommended.ExampleIn the following example we have two classes Super and Sub one extending the other. They both have two fields with same names (name and age).When we print ... Read More

3K+ Views
The valueOf() method of the Enum class in java accepts a String value and returns an enum constant of the specified type.ExampleLet us create an enum with name Vehicles with 5 constants representing models of 5 different scoters with their prices as values, as shown below −enum Vehicles { //Constants with values ACTIVA125(80000), ACTIVA5G(70000), ACCESS125(75000), VESPA(90000), TVSJUPITER(75000); //Instance variable private int price; //Constructor to initialize the instance variable Vehicles(int price) { this.price = price; } ... Read More

2K+ Views
In Java, after swing components displayed on the screen, they can be operated by only one thread called Event Handling Thread. We can write our code in a separate block and can give this block reference to Event Handling thread. The SwingUtilities class has two important static methods, invokeAndWait() and invokeLater() to use to put references to blocks of code onto the event queue.Syntaxpublic static void invokeAndWait(Runnable doRun) throws InterruptedException, InvocationTargetException public static void invokeLater(Runnable doRun)The parameter doRun is a reference to an instance of Runnable interface. In this case, the Runnable interface will not be passed to the constructor of a Thread. The Runnable interface is simply ... Read More

17K+ Views
Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }You can iterate the contents of an enumeration using for loop, using forEach loop and, using java.util.stream.Using for loopYou can retrieve the contents of an enum using the values() method. This method returns an array containing all the values. Once you obtain the array you can iterate it using the for loop.ExampleFollowing java program iterates ... Read More

2K+ Views
Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }You can also define an enumeration with custom values to the constants declared. But you need to have an instance variable, a constructor and getter method to return values.Enum with switch caseLet us create an enum with 5 constants representing models of 5 different scoters with their prices as values, as shown below −enum Scoters { ... Read More

8K+ Views
Enumeration (enum) in Java is a datatype which stores a set of constant values (Strings in general). You can use enumerations to store fixed values such as days in a week, months in a year etc.enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Custom values to the constantsInstead of declaring just string constants in an enum, you can also have values to these constants as −enum Vehicles { ACTIVA125(80000), ACTIVA5G(70000), ACCESS125(75000), VESPA(90000), TVSJUPITER(75000); }Whenever, you need to assign custom values to the constants of an enum −To hold the value of each ... Read More

4K+ Views
Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Methods and variables in an enumerationEnumerations are similar to classes and, you can have variables, methods, and constructors within them. Only concrete methods are allowed in an enumeration.ExampleIn the following example, we are defining an enumeration with name ... Read More

626 Views
Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Just like arrays, the elements/constants in an enumeration are identified using numbers starting from 0 in the above example the days are identified using numbers as shown in the following illustration −Retrieving values from an enumYou can retrieve all the ... Read More

779 Views
Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Points to keep in mindYou need to keep the following points in mind while declaring an enum −It is recommended to write the name of the constants in all capital letters as −public class EnumerationExample { enum Days { ... Read More

8K+ Views
Yes, you can.If you implement an interface and provide body to its methods from a class. You can hold object of the that class using the reference variable of the interface i.e. cast an object reference to an interface reference.But, using this you can access the methods of the interface only, if you try to access the methods of the class a compile time error is generated.ExampleIn the following Java example, we have an interface named MyInterface with an abstract method display().We have a class with name InterfaceExample with a method (show()). In addition to it, we are implementing the ... Read More