You are on page 1of 2

Class - Blue Print, Design - describe the states and behaviours

Object - is something which occupies real time memory. Object has states and
behaviours

what goes inside a class


1) Represents blue print of your object
2) Class must go with a pair of curly braces
3) Class can have one or more methods
4) syntax of class
accessModifier class ClassName
accessModifier - Public, Private and Global

Method:
1) It has collection of statements
syntax of method:
accessModifier returnType MethodName(arg1,arg2,...){
//Statements
}

if nothing is returned, specify return type as Void

Creating an apex class - dev console < file < New < Apex class < Name < Save

public class Dog {


public String Name;
public Integer Age;

public void disp(){


system.debug('Name of my dog : '+Name);
system.debug('Age of my dog : '+Age);
}
public String displayName(){
return Name;
}
}

Dog d1 = new Dog();


d1.Name = 'Scooby';
d1.Age = 4;
String dogName = d1.displayName();
system.debug('**dogName**'+dogName);

Dog d2 = new Dog();


d2.Name = 'Tiger';
d2.Age = 6;
d2.disp();

exercice: create a class called employee with variablse Name, Designation, Salary,
Age. Create multiple objects for this class

-----------
public class Dog {
public String Name;
public Integer Age;

public void disp(){


system.debug('Name of my dog : '+Name);
system.debug('Age of my dog : '+Age);
}
public static void method1(){
system.debug('In a static method');
}
}

Dog d1 = new Dog();


d1.Name = 'Dog1';
d1.disp();
Dog.method1();

Dog d2 = new Dog();


d2.Name = 'Dog1';
d2.disp();
Dog.method1();

You might also like