Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views8 pages

Oops Basic and Advanced

Uploaded by

Sameer Nadaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Oops Basic and Advanced

Uploaded by

Sameer Nadaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

OOPS BASIC AND ADVANCED

Deep copy and shallow copy

What is constructor creation

Different ways of constructor creation

What is an class

Polymorphism

Interitence and diff types of inheritance

Static functions

Super new

$cast

3 main criteria to use polymorphism

Parameterized classes

override methods

call backs

data encaptuation

typed constructor(what is the significance of scoped res in that)

Sure! Here are simple 2–3 line answers for each concept, just like a student would explain in a viva:

1. Difference between Object and Handle:

An object is the actual instance stored in memory. A handle is just a reference or pointer to that
object. Multiple handles can point to the same object.

2. Null Object Handle:

A null handle means it is not pointing to any object. Using it without assignment can cause errors or
null reference issues.


3. Constructor:

A constructor is a special method used to create and initialize an object. It runs automatically when
the object is created.

4. Shallow Copy vs Deep Copy:

A shallow copy copies the object but not the objects it points to (references stay the same). A deep
copy copies the object and also makes new copies of everything it refers to.

5. Static Function vs Function Static:

A static function belongs to the class, not to any object, and can be called without creating an object.
A static variable inside a function keeps its value between function calls.

6. Super and New:

super is used to call the parent class constructor or methods. new is used to create a new object or
allocate memory for a class.

7. Inheritance:

Inheritance means one class (child) can use the properties and methods of another class (parent). It
promotes reusability.

8. Polymorphism:

Polymorphism means one function or method behaves differently based on the object or input.
Example: method overloading and overriding.

Let me know if you want examples or diagram help too!

Callback is a way to pass a function (or object with a function) to another module or class, so that it
can call it later when needed.

🔁 Simple Example:

Think of it like giving your friend your phone number (function), so they can call you back when
something happens — like when a task is done.

In SystemVerilog, callbacks are often used in testbenches to let one class control or respond to
events in another without hardcoding the logic.

Here’s the difference between virtual and pure virtual methods in simple terms:

Virtual Method:

• Declared using the virtual keyword.

• It can be overridden in the child class, but it’s not mandatory.

• It may have a default implementation in the base class.

Pure Virtual Method:

• Declared like this: virtual function void myFunc(); = 0;

• It must be overridden in the child class.

• The base class becomes an abstract class (cannot create objects from it).

📝 Use virtual when you have a default behavior; use pure virtual when you just want to force child
classes to implement it.

Data Encapsulation means wrapping data (variables) and code (methods) together inside a class, and
hiding the internal details from outside.
🔒 We use private or protected access to restrict direct access, and provide public methods
(getters/setters) to access or modify the data safely.

📦 It protects the data and keeps the code clean and secure.

Typed Constructor is a constructor that includes input arguments with specific data types.

🧱 It allows you to initialize object properties with values when creating the object.

📌 Example in SystemVerilog:

class MyClass;

int x;

function new(int val); // typed constructor

x = val;

endfunction

endclass

✅ It helps in passing required values directly during object creation.

class MyTest;

...

virtual task body();

// some statements

pre_err_callback();

err_inj_seq();

post_err_callback();

// more statements

endtask

virtual task pre_err_callback();


// Empty callback

endtask

virtual task post_err_callback();

// Empty callback

endtask

endclass

class MyTestExt extends MyTest;

virtual task pre_err_callback();

// Implement things to be done before error injection

endtask

virtual task post_err_callback();

// Implement things to be done after error injection

endtask

endclass

module test;

MyModule mod;

MyCallbackImpl cb_obj;

initial begin

// Create objects

mod = new();

cb_obj = new();

// Set the callback

mod.set_callback(cb_obj);

// Perform operation that triggers the callback


mod.do_something();

end

endmodule. Explain this all the lines

// Callback base class

class MyCallback;

virtual function void notify(); // Virtual method to be overridden

endfunction

endclass

// Callback implementation class

class MyCallbackImpl extends MyCallback;

virtual function void notify();

$display(">> Callback: notify() function called!");

endfunction

endclass

// Main module/class that uses the callback

class MyModule;

MyCallback cb; // Handle to callback class

// Method to set the callback

function void set_callback(MyCallback obj);

cb = obj;

endfunction

// Method that does something and calls the callback

function void do_something();

$display(">> MyModule: Doing something...");

if (cb != null)

cb.notify(); // Call the callback if set

else
$display(">> No callback set.");

endfunction

endclass

// Testbench

module test;

MyModule mod;

MyCallbackImpl cb_obj;

initial begin

// Create objects

mod = new();

cb_obj = new();

// Set the callback

mod.set_callback(cb_obj);

// Perform operation that triggers the callback

mod.do_something();

end

endmodule

What is class ? and why is it a data type?

Difference between object and handle ?

What is null object handle ?

Explain constructor

Shallow copy vs deep copy

Static function vs function static

What is super.new?

Explain inheritance

Explain polymorphism and explain 3 main criteria for polymorphism

What is callback
What is data encapsulation

What is typed constructor

Write a code snippet for callback function

You might also like