0

This is a noob question

using System.name; class class_name { private className Obj; public class_name() { } public function() { Obj.function <----- why i cant acesss the global varible here ?? } } 

When i type the class the instellisence docent show any thing :-s

2 Answers 2

3

I'm assuming there was just some confusion with the names and, by function, you meant class_name, or instead of class_name you meant className.

In order to access a method this way, it must be declared as static. Otherwise, you must first create an instance of the class and access the method through the instance.

EDIT The code you posted is very confusing. The following works just fine for me.

class Class1 { public void Function1() { } } class Class2 { private Class1 obj; public void Function2() { obj.Function1(); } } 
Sign up to request clarification or add additional context in comments.

9 Comments

i already created a global private className Obj; but cannot acesss from the function because its not static ?
No, you've created a class member. And, again, if you don't declare the member as static, then you must create an instance of the class in order to access that member. If you want to access it this way, declare it as private static className obj;.
Fix your symbol names. It's very confusing. I think you've not used the same name for references to the same symbol.
private classsName Obj = new Classname(); but same prob !
Where is className declared? If you want help, can't you just take a minute and fix your errors?
|
1

Have you instantiated that class?

2 Comments

yep ! private className Obj;
@Sudantha Try private className obj = new className();

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.