Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6356491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:58:22+00:00 2026-05-24T22:58:22+00:00

* I made an array.. at the class level,but assigned it’s values inside a

  • 0

*I made an array.. at the class level,but assigned it’s values inside a method.. but for some reason.. it gave up an error..
then when i did the array declaration & assignment inside of the same method..
everything functioned smoothly!! Why is that? I declared the array at class level.. so it has class scope right?? so why can’t i assign it values inside a method?? I’m utterly confused :/ *

public class VacationScale{



public int [] days;

days = new int [7];


public void setVacationScale(){

    days[0]=10;
days[1]=15;
days[2]=15;
days[3]=15;
days[4]=20;
days[5]=20;
days[6]=25;

}

public void displayVacationDays(int yearsOfService){
    if(yearsOfService >=0 && yearsOfService<=6){
    System.out.println("the years of the service of the employee is "
        +yearsOfService+ " and hence the employee is eligible to :" 
        +days[yearsOfService]+ " holidays"); 
    }
    else if(yearsOfService >6){

        System.out.println("the years of the service of the employee is "
            +yearsOfService+ " and hence the employee is eligible to :25" 
        +" holidays"); 


    }
    else{
    System.out.println("invalid number of years of service");

    }

}

}

The error that shows up on the command prompt is– identifier expected

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:58:23+00:00Added an answer on May 24, 2026 at 10:58 pm

    The line days = new int [7]; is invalid code outside of a method. Instead write:

    public int [] days = new int [7];
    

    which will both declare and initialize the array.

    Beyond this, there is no need for your setVacationScale() method, since it appears to be hardcoded. Instead, you can initialize the array to have these values:

    public int [] days = new int[] {10, 15, 15, 15, 20, 20, 25};
    

    To give a few more tips, it’s unwise to expose access to the array outside the class if it’s only used by the class’s methods – if this is the case change its access modifier to private. And as long as the array is only initialized once, it’s good form to make it final:

    private final int [] days = new int[] {10, 15, 15, 15, 20, 20, 25};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static const array class member (const pointers to SDL_Surfaces, but that's
how can I make array of ArrayList or Pair Class which I made myself
Always was interested why are Array.Sort() and Array.IndexOf() methods made static and similar ArrayList.Sort()
I made a code that translate strings to match each word from the array
I made a class from Linq to SQL Clasees with VS 2008 SP1 Framework
I made a Java Applet with some Standard GUI Components on it. I used
I made a discovery some time back. Just follow these steps: Create a .doc/.xls/.ppt
I made a class that derives from Component: public class MyComponent: System.ComponentModel.Component { }
I made an html file called test.html then I navigated to it as http://site.com/test.html?test1=a
I am trying to get some errors returned in JSON format. So, I made

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.