![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 9326 Articles for Object Oriented Programming
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
857 Views
To pull distinct values in an array you need to compare each element of the array to all the remaining elements, in case of a match you got your duplicate element. One solution to do so you need to use two loops (nested) where the inner loop starts with i+1 (where i is the variable of outer loop) to avoid repetitions in comparison.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class DetectDuplcate { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size of the array that is to be ... Read More
![mkotla](https://www.tutorialspoint.com/assets/profiles/13540/profile/60_41073-1512640012.jpg)
1K+ Views
Java does not support multiple inheritance. This means that a class cannot extend more than one class. Therefore, following is illegal −Examplepublic class extends Animal, Mammal{}However, a class can implement one or more interfaces, which has helped Java get rid of the impossibility of multiple inheritance.The extends keyword is used once, and the parent interfaces are declared in a comma-separated list.For example, if the Hockey interface extended both Sports and Event, it would be declared as −Examplepublic interface Hockey extends Sports, Event
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
7K+ Views
To move an item from an ArrayList and add it to the first position you need to -Get the position (index) of the item using the indexOf() method of the ArrayList class.Remove it using the remove() method of the ArrayList class.Finally, add it to the index 0 using the add() method of the ArrayList class.ExampleLive Demoimport java.util.ArrayList; public class ArrayListSample { public static void main(String args[]) { ArrayList al = new ArrayList(); al.add("JavaFX"); al.add("HBase"); al.add("WebGL"); al.add("OpenCV"); System.out.println(al); String item = "WebGL"; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
55K+ Views
You can pass arrays to a method just like normal variables. When we pass an array to a method as an argument, actually the address of the array in the memory is passed (reference). Therefore, any changes to this array in the method will affect the array.Suppose we have two methods min() and max() which accepts an array and these methods calculates the minimum and maximum values of the given array respectively:Example Live Demoimport java.util.Scanner; public class ArraysToMethod { public int max(int [] array) { int max = 0; for(int i=0; imax) { ... Read More
![Sai Subramanyam](https://www.tutorialspoint.com/assets/profiles/13512/profile/60_68191-1512710774.jpg)
1K+ Views
In Java, you can create an array just like an object using the new keyword. The syntax of creating an array in Java using new keyword −type[] reference = new type[10];Where, type is the data type of the elements of the array.reference is the reference that holds the array.And, if you want to populate the array by assigning values to all the elements one by one using the index −reference [0] = value1; reference [1] = value2;You can declare an array of Strings using the new keyword as &mius;String[] str = new String[5]; And then, you can populate the string ... Read More
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
5K+ Views
We can return an array in Java from a method in Java. Here we have a method createArray() from which we create an array dynamically by taking values from the user and return the created array.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class ReturningAnArray { public int[] createArray() { Scanner sc = new Scanner(System.in); System.out.println("Enter the size of the array that is to be created:: "); int size = sc.nextInt(); int[] myArray = new int[size]; System.out.println("Enter the elements of the array ::"); for(int i=0; i
![Syed Javed](https://www.tutorialspoint.com/assets/profiles/13356/profile/60_64693-1512709676.jpg)
247 Views
JDK 1.5 introduced a new for loop known as foreach loop or enhanced for loop, which enables you to traverse the complete array sequentially without using an index variable.ExampleLive Demopublic class ArrayUsingForEach { public static void main(String[] args) { double[] myList = {1.9, 2.9, 3.4, 3.5}; for (double element: myList) { System.out.println(element); } } }Output1.9 2.9 3.4 3.5
![varma](https://www.tutorialspoint.com/assets/profiles/13568/profile/60_26300-1512638592.jpg)
947 Views
IS-A is a way of saying: This object is a type of that object. Let us see how the extends keyword is used to achieve inheritance.Examplepublic class Animal { } public class Mammal extends Animal { } public class Reptile extends Animal { } public class Dog extends Mammal { }Now, based on the above example, in Object-Oriented terms, the following are true −Animal is the superclass of Mammal class.Animal is the superclass of Reptile class.Mammal and Reptile are subclasses of Animal class.Dog is the subclass of both Mammal and Animal classes.Example Live Democlass Animal { } class Mammal extends Animal ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
402 Views
To process array elements, we often use either for loop or for each loop because all of the elements in an array are of the same type and the size of the array is known. Suppose we have an array of 5 elements we can print all the elements of this array as −ExampleLive Demopublic class ProcessingArrays { public static void main(String args[]) { int myArray[] = {22, 23, 25, 27, 30}; for(int i=0; i
![usharani](https://www.tutorialspoint.com/assets/profiles/13564/profile/60_32161-1512638316.jpg)
916 Views
If we perform (achieve) method overriding and method overloading using instance methods, it is run time (dynamic) polymorphism. In dynamic polymorphism the binding between the method call an the method body happens at the time of execution and, this binding is known as dynamic binding or late binding. Example Live Demo class SuperClass{ public static void sample(){ System.out.println("Method of the super class"); } } public class RuntimePolymorphism extends SuperClass { public static void sample(){ System.out.println("Method of the ... Read More