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 4086070
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:40:25+00:00 2026-05-20T18:40:25+00:00

From the SCJP Questions PDF book, I got this question.. 1. enum Animals {

  • 0

From the SCJP Questions PDF book, I got this question..

1. enum Animals {
2. DOG("woof"), CAT("meow"), FISH("burble");
3. String sound;
4. Animals(String s) { sound = s; }
5. }
6. class TestEnum {
7. static Animals a;
8. public static void main(String[] args) {
9. System.out.println(a.DOG.sound + " " + a.FISH.sound);
10. }
11. }

The Options are,

A. woof burble

B. Multiple compilation errors

C. Compilation fails due to an error
on line 2

D. Compilation fails due to an error
on line 3

E. Compilation fails due to an error
on line 4

F. Compilation fails due to an error
on line 9

A is the correct Answer,..

Can some body explain this..

Whether the enum can have constructors?

  • 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-20T18:40:26+00:00Added an answer on May 20, 2026 at 6:40 pm

    Yes, enums can have constructors and methods and instance variables just like other classes.
    But you cannot call the constructor yourself, like you would with a regular class.
    You can’t call a= new Dog(“wooooof”).
    The constructor will be called by the compiler for you.

    This will compile fine, but on line 9, I think the compiler will warn you that you are accesing a static field in a a non-static way. Animal.DOG.sound is the “proper way” and not a.DOG.sound.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is a question from Kathy & Bert Bates SCJP 5 preparation CD. I
While studying for the SCJP 6 exam, I ran into this question in a
I can't figure out an SCJP questions even after getting the right answer: From
Background info I have a query regarding a questions from Sierra & Bates, SCJP
reading the SCJP book, I've found something like this in the chapter 1 self-test
This code is taken from a SCJP practice test: 3. public class Bridge {
From LinkedIn API I got this hash: > #<LinkedIn::Mash all=[#<LinkedIn::Mash api_standard_profile_request=#<LinkedIn::Mash headers=#<LinkedIn::Mash > all=[#<LinkedIn::Mash
It's actually from SCJP 6 StudyGuide Exam310-065(MGH,2008) alt text http://www.freeimagehosting.net/uploads/1f37466409.png alt text http://www.freeimagehosting.net/uploads/03aaff252a.png alt
From time to time I see an enum like the following: [Flags] public enum
I'm preparing the SCJP exam with the almost official study book ("SCJP Sun Certified

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.