in Technology by
What are the Restrictions of the Static Method in JAVA?

1 Answer

0 votes
by
edited by

There are two main restrictions for the static method. They are:

  • The static method cannot use non-static data members or call a non-static method directly.
  • this and super keyword cannot be used with a static context.

Demo.java

  1. class Demo  
  2. {    
  3. int num=100;    //non-static variable   
  4. //static method  
  5. public static void main(String args[])  
  6. {    
  7. //trying to access non-static data member from static context  
  8. System.out.println(num);    
  9. }    
  10. }    

Output:

Static Function in Java


Related questions

0 votes
    What are the restrictions that are applied to the Java static methods?...
asked Nov 19, 2020 in Education by Editorial Staff
0 votes
    I am trying to understand Static methods in java. I have done a basic python before, so I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I am trying to understand Static methods in java. I have done a basic python before, so I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    Software is a computer software for which there are restrictions on use modification Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    What restrictions do double values in Salesforce have? 1. Age and scale 2. Scale and position 3. Size and time 4. Scale and precision...
asked Jun 28, 2021 in Technology by JackTerrance
0 votes
    Is it possible for the users to impose restrictions on storing elements in the SVN repository?...
asked Feb 21, 2021 in Technology by JackTerrance
0 votes
0 votes
    Can “this” be used within a static method?...
asked Mar 31, 2021 in Technology by JackTerrance
0 votes
    What should be the execution order, if a class has a method, static block, instance block, and ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
0 votes
    what can I do to use the getTotalScore method on the Program class to get the total of my scores ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    I am building a small website for fun/learning using a fairly standard Web/Service/Data Access layered ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I am building a small website for fun/learning using a fairly standard Web/Service/Data Access layered ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I am building a small website for fun/learning using a fairly standard Web/Service/Data Access layered ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I am building a small website for fun/learning using a fairly standard Web/Service/Data Access layered ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
...