Private

Sample Code

class A{  

private int data=40;  

private void msg(){System.out.println("Welcome to Wikitechy");}  

}  

  

public class Simple{  

 public static void main(String args[]){  

   A obj=new A();  

   System.out.println(obj.data);//Compile Time Error  

   obj.msg();//Compile Time Error  

   }  

}  

Output

Public

Sample Code

package pack;  

public class A{  

public void msg(){System.out.println("Welcome to Wikitechy");}  

}  

Output

Protected

Sample Code

package pack;  

public class A{  

protected void msg(){
System.out.println("Welcome to Wikitechy");
}  

}  

Output

Default

Sample Code

package pack;  

class A{  

  void msg(){System.out.println("Welcome to Wikitechy");}  

Output

Categorized in:

C++

Tagged in:

, , , , , , ,

Share Article:

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO