
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Is an array a primitive type or an object in Java?
Array is considered to be an object in Java. The reason behind this is that an array can be created using the ‘new’ keyword. The ‘new’ keyword/operator is always used to create an object. This is how an array is perceived as an object.
The direct parent class or super class of any array is the ‘Object’ class. Every array type in Java belongs to a certain class. This indicates that there are explicit classes for integer array types, float array types, double array types, and so on.
Arrays can be dynamically created, and be assigned variables as well.
Let us see an example −
Example
public class Demo{ public static void main(String[] args){ System.out.println("Is the argument an instance of super class Object? "); System.out.println(args instanceof Object); int[] my_arr = new int[4]; System.out.println("Is the array my_arr an instance of super class Object? "); System.out.println(my_arr instanceof Object); } }
Output
Is the argument an instance of super class Object? true Is the array my_arr an instance of super class Object? true
A class named Demo contains the main function and the ‘instanceof’ operator is used to check if ‘args’ is an instance of the Object and if the newly created array is an instance of the Object. The results are displayed on the console.
- Related Articles
- Is String a primitive data type or an object in Java?
- Prove that the interface for a primitive type is an empty array in Java
- Is array a primitive data type in Java?
- Convert double primitive type to a Double object in Java
- Get the Component Type of an Array Object in Java
- Convert short primitive type to Short object in Java
- Convert byte primitive type to Byte object in Java
- Determining If an Object Is an Array in Java
- How to convert an array of objects to an array of their primitive types in java?
- How to convert an object array to an integer array in Java?
- Get the name of a primitive type in Java
- What would getPackage() return for a primitive or array in unnamed package in Java?
- how can I declare an Object Array in Java?
- How to create an array of Object in Java
- Can you create an array of Generics type in Java?
