Class and Objects
Class and Objects
Class:
A Class is a user defined datatype (complex-type) and acts as a blueprint for their
instances.
String helloWorldString;
private static final String DEFAULT_STRING;
static{
DEFAULT_STRING = 'Hello World';
}
public Demo2(){
this(DEFAULT_STRING);
}
public Demo2(String stringToDisplay){
this.helloWorldString = stringToDisplay;
}
//Anonymous Window
Demo2 d21 = new Demo2();
d21.printOutput();
Non-primitive data type arguments, such as sObjects, are also passed into methods by
value. This means that when the method returns, the passed-in argument still references
the same object as before the method call, and can’t be changed to point to another
object. However, the values of the object’s fields can be changed in the method.
Demo3 – Pass by Value Vs Reference
public class Demo3 {