aspose file tools
The moose likes Beginning Java and the fly likes Inner class can not containt static varibales why? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Inner class can not containt static varibales why?" Watch "Inner class can not containt static varibales why?" New topic
Author

Inner class can not containt static varibales why?

Mohan Patidar
Greenhorn

Joined: Aug 28, 2011
Posts: 6
public class InnerClassEx
{


public InnerClassEx()
{
getData();
}

public void getData()
{
Inner in=new Inner();
in.display();

}
public class Inner
{
static int y; //error it cant be why
static final int x=20;
public void display()
{
//x=20;
System.out.println(x);
System.out.println("Inner Class");
}
}
public static void main(String s[])
{
new InnerClassEx();
}
}
AnujS Sharma
Greenhorn

Joined: Jul 30, 2011
Posts: 15
If you create a static variable y, then you can surely also create another static variable x.

Can't seem to figure out what the error here is. Can you give more details about the error that you are getting?
Mohan Patidar
Greenhorn

Joined: Aug 28, 2011
Posts: 6
in My program i have declared two variables x and y.....x is a final static variable and y is only static in inner class.....in inner class we can declare a static final variable but we can not declare static variable why?
AnujS Sharma
Greenhorn

Joined: Jul 30, 2011
Posts: 15
You can declare both of them.

What is the error that you are getting?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32712
    
    4
It's in the Java Language Specification.
AnujS Sharma
Greenhorn

Joined: Jul 30, 2011
Posts: 15
This is talking about Inheritance.

The code that you have provided does not use inheritance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner class can not containt static varibales why?
 
Similar Threads
Inner Class
inner classes
Inner classes -doubt on static
why a inner class cant have static variables?
final local variable question