Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me with the static class? What it means and why we should go for static class?

1 Answer

0 votes
by (26.7k points)

A static class can be created inside another class as a nested static class, which will not able to access the non-static data members and methods as well. Whereas, it can able to access the private data members.

class Intellipaat{  

  static int data=30;  

  static class InnerIntellipaat{  

   void msg(){System.out.println("Intellipaat's data is "+data);}  

  }  

  public static void main(String args[]){  

  Intellipaat.InnerIntellipaat obj=new Intellipaat.InnerIntellipaat();  

  obj.msg();  

  }  

}  

I hope this will help.

Want to become a Java Expert? join Java Training now!!

Related questions

0 votes
1 answer
asked Jan 25, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Oct 29, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...