0% found this document useful (0 votes)
36 views

What Is Polymorphism?

String objects are immutable, while StringBuilder objects are mutable. This allows StringBuilder to modify the length and content of a string even after it is created, while the length and content of a String cannot be modified once created. StringBuilder provides methods like Append, Reverse, and Remove to modify strings, and is generally more efficient than String for operations that repeatedly modify the string.

Uploaded by

manjimakakkadath
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

What Is Polymorphism?

String objects are immutable, while StringBuilder objects are mutable. This allows StringBuilder to modify the length and content of a string even after it is created, while the length and content of a String cannot be modified once created. StringBuilder provides methods like Append, Reverse, and Remove to modify strings, and is generally more efficient than String for operations that repeatedly modify the string.

Uploaded by

manjimakakkadath
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

String stringbuilder

Strings are immutable Stringbuilders are mutable


Strings are immutable that means, if using the append methods, u can
u store some characters in a string direclty concatenate more characters
and then concatenate some more to the existing string, the already
characters to it, the previously allocated memory will just be
allocated memory will be destroyed changed, it will not be destroyed and
and a new memory will be allocated reallocated.String builder is derived
for the new string from Syste.Text.
StringBulider Is more Effiecent Then
String B'Cuse It
Provide Some Standered Function like
Append,Reverse,Remove
System.String System.StringBuilder
Once the string object is created, its Even after object is created, it can be able
length and content cannot be modified. to modify length and content.

Slower Faster

What is Polymorphism?
Polymorphism means same operation may behave differently on different classes.
Example of Compile Time Polymorphism: Method Overloading
Example of Run Time Polymorphism: Method Overriding
- Method with same name but with different arguments is called method
overloading.
- Method Overloading forms compile-time polymorphism.
- Example of Method Overloading:
class A1
{
void hello()
{ Console.WriteLine(“Hello”); }

void hello(string s)
{ Console.WriteLine(“Hello {0}”,s); }
}

Example of Run Time Polymorphism

Method Overriding
- Method overriding occurs when child class declares a method that has the same type
arguments as a method declared by one of its superclass.
- Method overriding forms Run-time polymorphism.
- Note: By default functions are not virtual in C# and so you need to write “virtual”
explicitly. While by default in Java each function are virtual.
- Example of Method Overriding:
Class parent
{
virtual void hello()
{ Console.WriteLine(“Hello from Parent”); }
}

Class child : parent


{
override void hello()
{ Console.WriteLine(“Hello from Child”); }
}

static void main()


{
parent objParent = new child();
objParent.hello();
}
//Output
Hello from Child.

11.What’s the difference between the System.Array.CopyTo() and


System.Array.Clone()?
The Clone() method returns a new array (a shallow copy) object containing all the
elements in the original array. The CopyTo() method copies the elements into another
existing array. Both perform a shallow copy. A shallow copy means the contents (each
array element) contains references to the same object as the elements in the original
array. A deep copy (which neither of these methods performs) would create a new
instance of each element's object, resulting in a different, yet identacle object.

What is an interface class?


Interfaces, like classes, define a set of properties, methods, and events. But unlike classes,
interfaces do not provide implementation. They are implemented by classes, and defined
as separate entities from classes.

10. What’s the difference between an interface and abstract class?


In an interface class, all methods are abstract - there is no implementation. In an abstract
class some methods can be concrete. In an interface class, no accessibility modifiers are
allowed. An abstract class may have accessibility modifiers.
11. What is the difference between a Struct and a Class?
Structs are value-type variables and are thus saved on the stack, additional overhead but
faster retrieval. Another difference is that structs cannot inherit.

12. What does the keyword virtual mean in the method definition?
The method can be over-ridden.

8. Describe the accessibility modifier protected internal.?


It’s available to derived classes and classes within the same Assembly (and naturally
from the base class it’s declared in).

17. What’s an abstract class?


A class that cannot be instantiated. A concept in C++ known as pure virtual method. A
class that must be inherited and have the methods over-ridden.
Essentially, it’s a blueprint for a class without any implementation.

19. What’s an interface class?


It’s an abstract class with public abstract methods all of which must be implemented in
the inherited classes.

26. What’s the difference between System.String and System.StringBuilder classes?


System.String is immutable, System.StringBuilder was designed with the purpose of
having a mutable string where a variety of operations can be performed.

You might also like