Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Not able to access parent instance variable in outside of methods in child

UdayaShankaraGandhiJun 13 2012 — edited Jun 13 2012
Hi,

I am not getting why i am not able to access parent class instance variable outside the child class intance methods.
class Parent
{
	int a;
}

class Child extends Parent
{
	a = 1; // Here i am getting a compilation error that Syntax error on token "a", VariableDeclaratorId expected after this token
	
	void someMethod()
	{
		a = 1;  // Here i am not getting any compilation error while accessing parent class variable
	}
}
Can any one please let me know exact reason for this and what is the error talks about?

Thanks,
Uday

Edited by: Udaya Shankara Gandhi on Jun 13, 2012 3:30 AM
This post has been answered by walterln on Jun 13 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2012
Added on Jun 13 2012
1 comment
253 views