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

The Archive Base Latest Questions

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

I am writing some Java questions to help my friends in the Java exam.

  • 0

I am writing some Java questions to help my friends in
the Java exam. I wrote a question and I assumed
that three errors would occur in the code but the compiler
only complained about two. The code is:

class MyClass 
{ 
   static MyClass() 
    {  
     System.out.println("I am The First Statement here!"); 
       this();  
    } 
} 

I expected the following errors:

  1. the constructor can’t be static

  2. this can’t be in a static function (since the constructor isn’t valid)

  3. this here should be the first
    statement.

NetBeans isn’t complaining about the second error here. Why?

  • 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-14T22:46:59+00:00Added an answer on May 14, 2026 at 10:46 pm

    When compilers encounter errors, they try to avoid so-called “secondary errors” – errors resulting from other errors, by “fixing-up” earlier errors.

    For example, the compiler flags an error because of the malformed constructor declaration. It can interpret this as either a constructor, that you’ve tried to make static, or as a regular static method that is missing a declared return type. The compiler can fix up your declaration either by ignoring the static keyword, and treating it as a regular constructor, or it can treat it as a static method and “invent” a return type to make up for a missing return type.

    It sounds like NetBeans is taking the first approach – fixing up your constructor so that it is not static. When the compiler chooses to ignore the static keyword, to avoid secondary errors, the this() call is then valid, since the compiler sees that it is in a regular constructor, so the second error is not flagged. This is actually desirable behaviour – compiler writers go to great lengths to avoid secondary errors, since they cloud the “real” errors. As soon as you fix up the static constructor yourself and remove the static keyword, the this() call will then be valid (barring error #3.)

    To sum up – it’s the compiler trying to show you the real errors, rather than all the subsequent problems caused by those errors.

    EDIT: after an error, a compiler tries to recover by skipping over input to try to get back on track (to resync the tokenizer and parser to a known state). The portion they skip may have contained errors, or have caused an error in what the compiler subsequently correctly parses. Thus, error-recovery can lead to some errors not being reported. This is not significant from a correctness perspective – as long as the compiler flags one error (the original one that lead to error-recovery being required) that’s sufficient. Error handling and error reporting is primarily about usability. A compiler would be equally correct if it just printed “error” at the first error and left you to figure out where the error is – it just wouldn’t be very usable.

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

Sidebar

Ask A Question

Stats

  • Questions 410k
  • Answers 410k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The best you could probably do would be to find… May 15, 2026 at 7:24 am
  • Editorial Team
    Editorial Team added an answer To get the width and height of the viewport: var… May 15, 2026 at 7:24 am
  • Editorial Team
    Editorial Team added an answer There is an OS X version of graphviz, though I… May 15, 2026 at 7:24 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.