oops
oops
2. What is a class?
Class is an entity which consists of member data and member functions which operate
on the member data bound together.
3. What is an object?
Objects are instances of classes. Class is a collection of similar kind of objects. When a
class is created it doesn’t occupy any memory, but when instances of class is created i.e.,
when objects are created they occupy memory space.
4. What is encapsulation?
A1. Encapsulation is welding of code and data together into objects.
5. What is inheritance?
A2. Inheritance is a mechanism through which a subclass inherits the properties and
behavior of its superclass. The derived
class inherits the properties and method implementations of the base class and extends
it by overriding methods and adding additional properties and methods.
6. What is polymorphism?
A3. In Greek this means "many shapes."As a consequence of inheritance and virtual
functions, a single task (for example, drawing
a geometrical shape) can be implemented using the same name (like draw()) and
implemented differently (via virtual functions) as each type in object hierarchy
requires(circle.draw() or rectangle.draw()). Later, when a polymorphic object (whose
type is not known at compile time) executes the draw() virtual function, the correct
implementation is chosen andexecuted at run time.
7. What is the difference between function overloading and function overriding?
A. Overloading is a method that allows defining multiple member functions with the
same name but different signatures. The compiler will pick the correct function based
on the signature. Overriding is a method that allows the derived class to redefine the
behavior of member functions which the derived class inherits from a base class. The
signatures of both base class member function and derived class member function are
the same; however, the implementation and, therefore, the behavior will differ
Virtual tasks and functions are the ways to achieve the polymorphism in system verilog.
Try to fun the following example and see it will help you understand the concept.
class base ;
virtual function int print;
$display("INSIDE BASE \n");
endfunction : print
endclass : base
program test ;
derived d1;
initial
begin
d1 = new();
d1.print();
callPrint (d1);
end
endprogram
A virtual class is a temple or place holder for the child classes. A virtual class is
also called as the abstract class. A virtual class is declared with a virtual keyword
like :
virtual class base;
endclass;
A virtual class instance or object can not be constucted but you can define the
hadle to the virtual class.
A virtual class is a temple or place holder for the child classes. A virtual class is also
called as the abstract class. A virtual class is declared with a virtual keyword like :
virtual class base;
virtual task1;
endtask;
virtual task2;
endtask;
endclass;
A virtual class instance or object can not be constucted but you can define the hadle to
the virtual class.
virtual class baseframe;
...
virtual function void iam();
endfunction
...
endclass
class shortframe extends baseframe;
...
function void iam();
$display ("Short Frame");
endfunction
endclass
baseframe two; // OK
initial begin
two = new(4); // ERROR
...
Object Class
Objects take memory space when they are A class does not take memory space when
created created
17.What is inheritance?
Inheritance is a feature of OOPs which allows classes inherit common properties from
other classes. For example, if there is a class such as ‘vehicle’, other classes like ‘car’,
‘bike’, etc can inherit common properties from the vehicle class. This property helps you
get rid of redundant code thereby reducing the overall size of the code.
18. What are the different types of inheritance?
• Single inheritance
• Multiple inheritance
• Multilevel inheritance
• Hierarchical inheritance
• Hybrid inheritance
• Any modifications to the program would require changes both in the parent as
well as the child class
• Needs careful implementation else would lead to incorrect results
16. What is a superclass?
A superclass or base class is a class that acts as a parent to some other class or classes.
For example, the Vehicle class is a superclass of class Car.
17.What is a subclass?
A class that inherits from another class is called the subclass. For example, the class Car
is a subclass or a derived of Vehicle class.
18.What is polymorphism?
Polymorphism refers to the ability to exist in multiple forms. Multiple definitions can
be given to a single interface. For example, if you have a class named Vehicle, it can have
a method named speed but you cannot define it because different vehicles have
different speed. This method will be defined in the subclasses with different definitions
for different vehicles.
19. What is static polymorphism?
Overloading Overriding
Two or more methods having the same Child class redefining methods present in
name but different parameters or the base class with the same parameters/
signature signature
Encapsulation refers to binding the data and the code that works on that together in a
single unit. For example, a class. Encapsulation also allows data-hiding as the data
specified in one class is hidden from other classes.
26. What are ‘access specifiers’?
Access specifiers or access modifiers are keywords that determine the accessibility of
methods, classes, etc in OOPs. These access specifiers allow the implementation of
encapsulation. The most common access specifiers are public, private and protected.
However, there are a few more which are specific to the programming languages.
27. What is the difference between public, private and protected access
modifiers?
Private Yes No No
• Abstract method
30. What is an abstract class?
An abstract class is a class that consists of abstract methods. These methods are
basically declared but not defined. If these methods are to be used in some subclass,
they need to be exclusively defined in the subclass.
Can you create an instance of an abstract class?
No. Instances of an abstract class cannot be created because it does not have a complete
implementation. However, instances of subclass inheriting the abstract class can be
created.
32. What is an interface?
It is a concept of OOPs that allows you to declare methods without defining them.
Interfaces, unlike classes, are not blueprints because they do not contain detailed
instructions or actions to be performed. Any class that implements an interface defines
the methods of the interface.
33. Differentiate between data abstraction and encapsulation.
Allows showing important aspects while Binds code and data together into a single
hiding implementation details unit and hides it from the world
Class Method