- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 9313 Articles for Object Oriented Programming
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
780 Views
The final static field variable is a constant variable. There is only one copy of this variable available. It is mandatory to initialize the final static field variable explicitly as the default value for it is not provided by the JVM. Also, this variable cannot be reinitialized.A program that initializes the final static field variable using a static initialization block is given as follows:Example Live Demopublic class Demo { final static int num; static { System.out.println("Running static initialization block."); num = 6; } public static void main(String[] args) { ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
2K+ Views
The HashCode for an Integer can be obtained using the hashCode() method in Java. This method does not accept any parameters and it returns a hash code value of the Integer object.A program that demonstrates the hashCode() method in Java is given as follows:Example Live Demoimport java.lang.*; public class Demo { public static void main(String args[]) { Integer i = new Integer(60); System.out.println("The integer value is: " + i); System.out.println("The Hashcode for the above value is: " + i.hashCode()); } }OutputThe integer value is: 60 The Hashcode for the above ... Read More
![Fendadis John](https://www.tutorialspoint.com/assets/profiles/13534/profile/60_64028-1512539837.jpg)
167 Views
The hashCode() method is used to obtain the hash code for a string. This method does not accept any parameters as it is a default method and it returns a hash code value.A program that demonstrates the hashCode() method in Java is given as follows:Example Live Demoimport java.io.*; public class Demo { public static void main(String args[]) { String str = new String("The sky is blue"); System.out.println("The string is: " + str); System.out.println("The Hashcode for the string is: " + str.hashCode()); } }OutputThe string is: The sky is blue The ... Read More
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
1K+ Views
When a garbage collector determines that no more references are made to a particular object, then the finalize() method is called by the garbage collector on that object. The finalize() method requires no parameters and does not return a value.A program that demonstrates the finalize() method in Java is given as follows:Example Live Demoimport java.util.*; public class Demo extends GregorianCalendar { public static void main(String[] args) { try { Demo obj = new Demo(); System.out.println("The current time is: " + obj.getTime()); obj.finalize(); ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
5K+ Views
A string representation of an object can be obtained using the toString() method in Java. This method is overridden so that the object values can be returned.A program that demonstrates this is given as follows:Example Live Democlass Student { private int rno; private String name; public Student(int r, String n) { rno = r; name = n; } public String toString() { return rno + " " + name; } } public class Demo { public static void main(String[] args) { Student ... Read More
![Fendadis John](https://www.tutorialspoint.com/assets/profiles/13534/profile/60_64028-1512539837.jpg)
731 Views
Static import means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static.The Math class methods sqrt() and pow() in the package java.lang are static imported. A program that demonstrates this is given as follows:Example Live Demoimport static java.lang.Math.sqrt; import static java.lang.Math.pow; public class Demo { public static void main(String args[]) { double num = 4.0; System.out.println("The number is: " + num); System.out.println("The square root of the above number is: " + sqrt(num)); ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
15K+ Views
Static import means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static.The Math class method sqrt() in the package java.lang is static imported.A program that demonstrates this is given as follows:Example Live Demoimport static java.lang.Math.sqrt; public class Demo { public static void main(String[] arg) { double num = 36.0; System.out.println("The number is: " + num); System.out.println("The square root of the above number is: " + sqrt(num)); } }OutputThe number is: 36.0 The square root ... Read More
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
11K+ Views
All the classes in a package can be imported using the import statement along with the character *. For example - All the classes in the package java.util can be imported using import java.util.*;A program that demonstrates this in Java is given as follows:Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]) { Stack stack = new Stack(); stack.push("Apple"); stack.push("Mango"); stack.push("Guava"); stack.push("Pear"); stack.push("Orange"); System.out.println("The stack elements are: " + stack); } }OutputThe stack elements ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
73K+ Views
An interface contains variables and methods like a class but the methods in an interface are abstract by default unlike a class. Multiple inheritance by interface occurs if a class implements multiple interfaces or also if an interface itself extends multiple interfaces.A program that demonstrates multiple inheritance by interface in Java is given as follows:Example Live Demointerface AnimalEat { void eat(); } interface AnimalTravel { void travel(); } class Animal implements AnimalEat, AnimalTravel { public void eat() { System.out.println("Animal is eating"); } public void travel() { System.out.println("Animal is travelling"); ... Read More
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
219 Views
An interface can be defined using the interface keyword. It contains variables and methods like a class but the methods in an interface are abstract by default unlike a class. An interface is primarily used to implement abstraction and it cannot be instantiated.A program that demonstrates an interface in Java is given as follows:Example Live Demointerface AnimalSound { abstract void sound(); } class CatSound implements AnimalSound { public void sound() { System.out.println("Cat Sound: Meow"); } } class DogSound implements AnimalSound { public void sound() { System.out.println("Dog Sound: Bark"); } } ... Read More