- 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
Can a Java array be declared as a static field, local variable or a method parameter?
We can declare an array as a local variable or method parameter but, an array cannot be static.
Example
public class Test{ public void sample(){ static int[] myArray = {20, 30}; System.out.println(); } public static void main(String args[]){ Test t = new Test(); t.sample(); } }
Error
C:\Sample>javac Test.java Test.java:3: error: illegal start of expression static int[] myArray = {20, 30}; ^ 1 error
- Related Articles
- Can we declare a static variable within a method in java?
- Can we override a private or static method in Java
- Can we overload or override a static method in Java?\n
- Get the declared method by name and parameter type in Java
- How to pass a lambda expression as a method parameter in Java?
- Can I use a JavaScript variable before it is declared?
- Can a method local inner class access the local final variables in Java?
- How to declare a local variable in Java?
- Set tuple as a method parameter in C#
- Can we have a private method or private static method in an interface in Java 9?\n
- Can We declare main() method as Non-Static in java?
- Why can't static method be abstract in Java?
- Can a local variable's memory be accessed outside its scope in C/C++?
- What are the restrictions imposed on a static method or a static block of code in java?
- Can constructors be marked final, abstract or static in Java?

Advertisements