Java / Class Variables (Static Variables)
What is a static class in Java?
A Class can be made static only if it is a nested class (class within a class). The nested static class can be accessed without having an object of outer class.
It can access static data members of outer class including private. Static nested class cannot access non-static data member or method.
If you have the static member inside static nested class, it can be accessed directly and you don't have to create instance of static nested class.
The static class are also known as static nested class or static inner class .
class OuterClassEx{ static int val=30; static class InnerClassEx{ void msg(){System.out.println("Value is "+val);} } public static void main(String args[]){ OuterClassEx.InnerClassEx obj=new OuterClassEx.InnerClassEx(); obj.msg(); } }
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
