DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Coding
  3. Languages
  4. Static Members in Inner Classes? The Answer

Static Members in Inner Classes? The Answer

Zviki Cohen user avatar by
Zviki Cohen
·
Jul. 28, 08 · Interview
Like (0)
Save
Tweet
Share
8.08K Views

Join the DZone community and get the full member experience.

Join For Free

i asked a question a few days ago , regarding static members in inner classes. i presented an example with two static members, one was integer the other object type, the integer compiled correctly and the object did not. here's how it looks like in the ide:

java riddle

the answer is found in the java language specification 3rd edition , section 8.1.3 :

inner classes may not declare static members, unless they are compile-time constant fields

that's the answer. the integer is a compile-time constant which is in-lined by the compiler. the object is not. here are some more examples:

java-riddle-3

by the way, if the class was a static nested class, rather than an inner-class, there wouldn't be any problem defining static members. plus, constants are inherited when using extensions. this means that the following is legit:

java-riddle-4


imho, java is not a complex language. it is much simpler than c++, for sure. however, it does have some odd edges.
from http://zvikico.typepad.com/problog
Java language Data Types Object (computer science) Java (programming language) c++ Plus (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Cucumber.js Tutorial With Examples For Selenium JavaScript
  • Stress Testing Tutorial: Comprehensive Guide With Best Practices
  • What’s New in the Latest Version of Angular V15?
  • Fixing Bottlenecks in Your Microservices App Flows

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: