function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaurav RajGaurav Raj 

Private variables being accessed outside the class without using the GET SET method

Hi,

I was using the DEVELOPER CONSOLE, in my Public class i had  two variables. inspite of declaring those variables as PRIVATE, i was accessing its values outside my class, but it shouldn't have been this way. if i was use the PRIVATE variables outside my Class, i should have use GET SET methods inside my class. for eg: the program goes like this

 

public class SFDC{
private string name;
private integer num;

private integer getnum(){
return num;}

}

SFDC sf = new SFDC();
sf.name='GAURAV';
sf.num=100;
system.debug(sf.getnum());

Bhawani SharmaBhawani Sharma
You can only access public variable outside the class, no matter if it has get set or not.