This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Compilation Error  RSS feed

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class x
{

x()
{
int i=0;
static int j;
System.out.println("I::" + i);
System.out.println("J::" + j);
}
x(int k)
{
int i=k;

System.out.println("I::" + i);
System.out.println("J::" + j);
}
}

class y extends x
{

y()
{
super(0);
int k=0;
static int l;
System.out.println("K::" + k);
System.out.println("L::" + l);
}
}

public class Test {
public static void main(String ar[])
{
y s = new y();

}
}

Why am I getting Illeagal start of Expression at line number 6???
And what is the order of initialization of variables/Class varibales when the class Y is instaced?

Thanks
Srinivas Ivaturi
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why am I getting Illeagal start of Expression at line number 6???


static modifier can not be used inside a method or construstor.


And what is the order of initialization of variables/Class varibales when the class Y is instaced?


Sorry... i didn't quite get your question. Do you mean what is the order in which variables are initialized when object 's' is created?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivaturi,
The problem is that you define a static variable in a method. Method variables are stored on the stack and therefor they can't a static.
greetings,
Jeroen
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside a method, variables may be declared only final.
 
Ivaturi Srinivas
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Everybody
My second question is How the Fileds are intitialized when the class Y is Instanced?
Ex:
Static
Instance variables
Constructor Instance Variables
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first of all class variables are created upon the creation of the object, then followed by the constructor/method variables in the order they are called.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!