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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:15:53+00:00 2026-05-24T07:15:53+00:00

Possible Duplicate: Cannot refer to a instance method while explicitly invoking a constructor I

  • 0

Possible Duplicate:
Cannot refer to a instance method while explicitly invoking a constructor

I have been trying to do this for long time.

public class bb extends test {

    int t = 23;

    public bb() {
        super(t); //**This is the place that error comes**
        // TODO Auto-generated constructor stub
    }

    public bb(int v) {
    }
}

public class test {

    public test() {
        // TODO Auto-generated constructor stub
    }

    public test(int v) {
        // TODO Auto-generated constructor stub
    }
}

Controller class

class s {   
    public static void main(String[] args) {

        bb sd = new bb();
        System.out.println("sdfsdfsdfd");
    }
}

This is the error that comes. I want to know why a instance variable can’t be passed to a super class constructor? I suspect that it’s because there is no instance accessible to the constructor.

Exception in thread “main” java.lang.Error: Unresolved compilation problem:
Cannot refer to an instance field t while explicitly invoking a constructor

  • 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-24T07:15:54+00:00Added an answer on May 24, 2026 at 7:15 am

    If you make that variable as a static variable that error will disappear.. this happens because

    Instance Variables are created once its constructor is called but here in this case before the

    child's constructor its parent Constructor gets executed.. which means instance variables/object of

    child class doesn’t exist in the Heap. or in other words they are not constructed yet.. but in case

    of static variables they are first one’s getting executed thus they have some values and that works

    perfectly fine..

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

Sidebar

Related Questions

Possible Duplicate: non static method cannot be referenced from static context hey i have
Possible Duplicate: Cannot connect to UserPC\SQLExpress I have been struggling to find a solution
Possible Duplicate: Cannot set boolean values in LocalStorage? So i've been trying to get
In SQL its possible to have fields that cannot contain duplicate data. How is
Possible Duplicate: R cannot be resolved - Android error The errors I have are
Possible Duplicate: C# Cannot convert from IEnumerable<Base> to IEnumerable<Derived> I have D1 and D2
Possible Duplicate: Conditional operator cannot cast implicitly? I have run into a peculiar situation
Possible Duplicate: Cannot refer to a non-final variable inside an inner class defined in
Possible Duplicate: Interface defining a constructor signature? I know that you cannot specify a
Possible Duplicate: What is System.Void? I have no practical reason for knowing this answer,

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.