Class Data Type
Class Data Type
//method-1
task set(int i);
x = i;
endtask
//method-2
function int get();
return x;
endfunction
endclass
Class Instance and Object Creation
• Class properties and methods can be accessed only after creating the
object.
class_1 = new();
Accessing class properties and methods
//method-1
task set(int i);
x = i;
endtask
//method-2
function int get();
return x;
endfunction
endclass
module sv_class_ex;
sv_class class_1; //Creating Handle
initial begin
sv_class class_2 = new(); //Creating handle and Object
class_1 = new(); //Creating Object for the Handle
//Accessing Class methods
class_1.set(10);
class_2.set(20);
$display("\tclass_1 :: Value of x = %0d",class_1.get());
$display("\tclass_2 :: Value of x = %0d",class_2.get());
end
endmodule
Example code
class aiit;
int no_of_students; //properties
int y ;
task display();
$display("I am in display task Y = %0x , a = %0x , B = %0x, no_of_students = %0x", y,a,b,no_of_students);
endtask
endclasss
module tb();
aiit aiit_ob1;
aiit aiit_obj2, aiit3;
initial begin
aiit_obj1 = new();
aiit_obj2 = new();
aiit3 = new();
aiit_obj1.no_of_students = 10; //accessing property from outside of the class
aiit_obj1.mult(10,20);
aiit_obj1.display();
aiit_obj2.no_of_students = 10; //accessing property from outside of the class
aiit_obj2.mult(10,20);
aiit_obj2.display();
end
endmodule