Scope of the method
  • Here I learned you can call an external method as long as it is declared as a public method
  • The private methods can only be used by the local members (the same class)

//import java io.*;
public class Test_this
public static void main(String args[])//this is an netry function must have
//nameoftheclass varablea = new Nameofthecxlass();
A a=new A();
String str = "manas";
int n1;

class A
String str = "baba";
private void method1()
System.out.println("hello, my name is : " + str);
int method2(String str)
A x = new A();
this.str = str;
System.out.println("hello world : " + str);
return 0;

Supporting Image: Note that as soon as you create an object from a class, all the class members are accessible through the object "a", since method1() is declared as private, only method2() in class A is accessible outside the class. However, method2() can call method1(), because these two methods belong to same class.