UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

if we create a main method in a static nested class then run a program by the command Outerclass$Innerclass why?

Asked by Last Modified  

3 Answers

Learn Java

Follow 0
Answer

Please enter your answer

The static variable can be used to refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc. The static variable gets memory only once in class area at the time of class loading.
Comments

Trainer

What is interesting here is that when we compile a file that contains an inner class, we actually end up with two class files and not one. Because of the fact that the inner class is technically a separate class, a separate class file will be created for it as well -- which can see with the “OuterClass$InnerClass.class”...
read more
What is interesting here is that when we compile a file that contains an inner class, we actually end up with two class files and not one. Because of the fact that the inner class is technically a separate class, a separate class file will be created for it as well – which can see with the “OuterClass$InnerClass.class” class file. The dollar sign is used to separate the inner class name from the outer class name. But, we will not be allowed to run the command above, because an inner class can not have any static members at all – and that includes “public static void main()”. This is because we would not be able to access the instance variables of the outer class from within a static context of the inner class. And, if there were a static method inside the “inner class” it wouldn’t even be an inner class – it would technically have to be declared with the static modifier and therefore it would be a static nested class. So, this means that the only way that we can access an inner class is by creating an actual instance of the outer class. And this also means that we can only access the inner class at runtime when we already have an instance of the outer class that we can use to access the inner class. read less
Comments

Professional Tutor with 15 years of experience.

After compilation the CLASSfile for inner class iis Outerclass$Innerclass
Comments

View 1 more Answers

Related Questions

What is the difference between abstraction and encapsulation?
Encapsulation is wrapping, just hiding properties and methods. Encapsulation is used for hide the code and data in a single unit to protect the data from the outside the world. Class is the best example...
Neval
Can Anybody explain Internal code of HashMap?
Now we can synchronize map also by using collections. Synchronize method need to pass map Object as parameter...
Ramakanth
What are the advanced features of EJB3.1?
1. Support for direct use of EJBs in the servlet container, including simplified packaging options. The current thought is to allow EJBs in the WEB-INF/classes directory while allowing ejb-jar.xml to reside...
Arunava Chatterjee

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Recommended Articles

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more