# Same class names in different files

**URL:** <https://verificationacademy.com/forums/t/same-class-names-in-different-files/31918>\
**Category:** UVM\
**Tags:** sequencerdriver-class-name, UVM, class, virtual-sequence\
**Created:** [June 9, 2016, 5:23am UTC](https://verificationacademy.com/forums/t/same-class-names-in-different-files/31918 "2016-06-09T05:23:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpattaje](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/mpattaje/32/2477_2.png) [@mpattaje](https://verificationacademy.com/forums/u/mpattaje)\
**Post date:** [June 9, 2016, 5:23am UTC](https://verificationacademy.com/forums/t/same-class-names-in-different-files/31918/1 "2016-06-09T05:23:11Z")

</div>

Hi,

I have taken up verification of a subsystem. It has a 3rd party UVC, which has a file name cpu\_virtual\_sequence.sv and it has the line below:

```verilog
class virtual_sequence extends uvm_sequence;

```

My predecessor had added one more file called top\_virtual\_sequence.sv file at one hierarchy up and it has the same line below:

```verilog
class virtual_sequence extends uvm_sequence;

```

This was compiling and running fine. Now I have changed the top\_virtual\_sequence.sv as below (as part of clean up and good coding guideline):

```verilog
class top_virtual_sequence extends uvm_sequence;

```

This change gives compile error (which is related to the UVC). My question is:  
Is it possible to have same class name inside two different files?

Thanks,  
mpattaje

---

<div class="post-metadata">

**Author:** ![rohitk](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/a698b9/32.png) [@rohitk](https://verificationacademy.com/forums/u/rohitk)\
**Post date:** [June 9, 2016, 6:00am UTC](https://verificationacademy.com/forums/t/same-class-names-in-different-files/31918/2 "2016-06-09T06:00:27Z")

</div>

_In reply to [mpattaje](https://verificationacademy.com/forums/t/same-class-names-in-different-files/31918):_

Yes if they belong to different packages.

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 9, 2016, 6:03am UTC](https://verificationacademy.com/forums/t/same-class-names-in-different-files/31918/3 "2016-06-09T06:03:56Z")

</div>

_In reply to [mpattaje](https://verificationacademy.com/forums/t/same-class-names-in-different-files/31918/2):_

Of course you can. But you are overwriting the first class definition with the second one when compiling the code, i.e. you could exclude the first class definition from the compile. When you are renaming this sequence you are doing something differently.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [June 9, 2016, 2:59pm UTC](https://verificationacademy.com/forums/t/same-class-names-in-different-files/31918/4 "2016-06-09T14:59:36Z")

</div>

_In reply to [mpattaje](https://verificationacademy.com/forums/t/same-class-names-in-different-files/31918/3):_  
You can declare two of the same class names as long as they are declared in different scopes. It does not matter if they are in the same file or different files; they need to be in different scopes, otherwise that is a compilation error.  
Then you need to be careful of how you reference the class name if you are outside the scope where the class is declared. If the class is declared in a package, you can choose which package to import, or you can explicitly reference the package\_name::class\_name.
