Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the num variable in both of my inner and outer classes.. i just want to excess the outer class variable from the inner class variable using the inner class method..how do i do that?

how do i make objects or any change to excess that from my inner class method...??

IMP : I WANT TO EXCESS THE OUTER CLASS ELEMENT FROM THE INNER CLASS METHOD ONLY, NOT ANY OTHER WAY....

C#
import java.util.*;
import java.lang.*;
class Outer_demo
{
	int num=23; // i want to excess this element... how to do that?
	public class Inner_demo
	{
		int num=113;
		public void print()
		{
			System.out.println("this is an inner class with num value " + num); // here num value will be 113 ....
		}
	} //inner class ends
	void display_inner()
	{
		Inner_demo e = new Inner_demo();
		e.print();
	} 

}


What I have tried:

i havent tried much .. almost some of the changes .i.e creating inner class initittive but it was not much helpful.. so please do help me..everything you need is written in the comments.. please do read it carefully..


Thanks.
Posted
Comments
Richard MacCutchan 17-Aug-16 10:30am    
Use a different name for the inner variable.
shivam gohel 17-Aug-16 11:36am    
thats not i want... let them be with the same name .. what i have written is perfectly correct sir..
Richard MacCutchan 17-Aug-16 11:50am    
Yes it is perfectly correct. But it will not do what you want.
shivam gohel 17-Aug-16 12:19pm    
gentleman! my question is how to achieve the task i want without changing the name of any of the variable..

is it possible to do without changing the name of the variable...?
Richard MacCutchan 17-Aug-16 13:05pm    
No. The variable called num in the inner class will always be the one chosen. There is no sensible reason to have both variables with the same name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900