1.) What is object oriented programming (oops) Language?
oops is is a methodology to write the program where we specify the code in form of classes and objects .oops supports three important features which are given below:
4.) Which property of an object oriented programming is known as data hiding or information hiding? oops is is a methodology to write the program where we specify the code in form of classes and objects .oops supports three important features which are given below:
- Encapsulation
- Inheritance
- Polymorphism
Note:- Abstraction is also basic oops concepts feature.But mainly three important feature of oops.
2.) What is object based Language?
Object based language supports all features of oops except two features which are given below:
3.) What are three principle of an object oriented language?
- Encapsulation
- Inheritance
- Polymorphism
Encapsulation
5.) What is Class in c#?
A Class is a user-defined data type with a template that servers to define its properties.
6.) How does declare the Class in c#?
Syntax:
Class classname
{
}
OR
Class classname
{
Variable declaration;
Method declaration;
}
7.) Which types of properties includes in c# class ?
- Indexers
- Operators
- Constructors
- Destructors
8.) What is instance variables in c# ?
Data is encapsulated in a class by placing data fields inside the body of the class .These variables are called instance variables.We can create the instance variables exactly the same way as we create local variable.
Ex.
Class student
{
string name; //instance variables
int age ; //instance variables
money salary; //instance variables
}
9.) What is an object in c# ?
An object is Run time entity of any class,structure or union.
EX.
Class student
{
int x=10;
int y = 20;
public void display()
{
console.WriteLne(+x);
console.WriteLne(+y);
}student st = new student() //object "st" created
st.display(); // Here "st" object is calling the display method of student class
}
10.) What is difference between object and instance ?
11.) What is Method and how to declare it in class ?
An method is used for manipulating the data contained in the class.Methods are used always declared inside the body of the class.
EX.
class student
{
string name ;
int age ;
public void GetData (string s,int x)
{
name = s;
age = x ;
console.WriteLine(+s);
console.WriteLine(+x);
}
}
12.) Can we placed method definition before instance variable in c# ?
Yes.
13.) Can we access the variable declared in other method within same class ?
NO.
14.) What is access-specifier or modifier in c# ?
More Details....
15.) How can create an object of class in c# ?
C# uses New operator to create the object of the class.
Syntax:
classname objectname = new classname();
OR
classname objectname;
objectname=new classname();
EX.
student st = new student();
OR
student st;
st = new student();
16.) Can we create more than one object of a class in c# ?
Yes, all object are independent to each other ,means each have your copy of instance variable.
17.) What is the syntax for accessing the class member in the class ?
Syntax:
objectname . variable name ;
objectname.methodname(parameter-list);
18.) What is constructor in c# ?
A constructor is like a method,It is used to initialization of data member of the class member , when it is created.
There are some properties of constructor in c#.
- The name of constructor should be same as class name.
- Constructors can be public,private or protected in the class.
- Constructor are automatically called when object of class is created.
Yes.
20.) What is partial class in c# ?
More Details...21.) What is use of 'this' keyword in c# ?
There are some reason to use this keyword in c#.which are given below:
- If we want to refer the current member of the current class then we can use 'this ' keyword to refer that member.
- If we want to call a specific constructor of class through another constructor of same class the we can specify 'this' keyword without constructor.
- We can use 'this' keyword when variable name and object name is same.
22.) What is Destructor in c# ?
Destructor is a method that is called when a object is no more required.The name of destructor is same as the class name.It is use prefix '~' .It is used ,to deallocate the memory used by resources within the class.
More Details...
23.) Can we use Nested classes,structs,interfaces and enums in c# ?
Yes.
24.) What is Constant members in class and its use in c# ?
It is used to declared the data fields of class as constant
EX.
public const int size =200;
In above Example,member size is assigned by 200 at compile time and can not be changed later.
Constant members are implicitly static often,we can not declare them explicitly using static.
EX.
public static const int size =200;
it is wrong ,it will give compile time error.
25.) What is Readonly members in c# ?
Readonly are basically used to set the constant value at run time.Once value is assigned at run time then you can not change later.
EX.
class student
{
public readonly int x;
public static readonly int y;
public student (int a)
{
m=x;
}
static student()
{
y=50;
}
}
26) What is properties in c# ?
More Details..
27) What is Indexer in c# ?
More Details..
Note:- Indexers are sometimes referred to as 'smart arrays'.
28) What is difference between property and Indexer in c# ?
- Indexer is always an instance member whereas property can be static member.
- A Get accessor of a property corresponds to a method with no parameters whereas a Get accessor of an indexer's method the same formal parameter as the indexer.
- A Set accessor of a property corresponds to a method method with the same formal parameter named value,whereas a set accessor of an indexer corresponds to a method with the same formal parameter list as the indexer and the parameter named value.
- In Indexer,If we declare a local variable with same name as an indexer parameter then it will give error.
29) What is difference between static and Non static member in c# ?
More Details..
30) What is Inheritance in c# ?
In Inheritance, reusability is achieved by designing new classes.Means Derived class inherits the properties of parents class.
More Details..
31) What is Encapsulation in c# ?
More Details..
32) What is Polymorphism in c# ?
Polymorphism,permits the same method name to be used for different operations in different classes.
More Details..
33) What is different form of inheritance in c# ?
- Classical inheritance
- Containment inheritance
34) What is Classical inheritance ?
A classical inheritance supports the "is relationship" between two classes. In this we can create a class hierarchy such that derived class B form , from the parent class A as shown below:35) What are the types of Classical inheritance ?
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
A containment Inheritance supports the "has relationship" between two classes.
EX.
class Teacher
{
..........................
}
class student
{
Teacher T; //Teacher is contained in student.
student s;
.................................................................
}
In this ,object of Teacher(T) is contained in the object of student(s).Means when we create the object of student class then we can easily access the Teacher class member without creating the object of Teacher class.
37) How can we define the subclass in c# ?
When we define any sub class then we use : (colon operators).
Syntax:
class subclass-name : Base classname
{
variables declaration;
Method declaration;
.........................................
}
Ex.
class student :Teacher
{
.....//includes the Teacher all fields here.
.....//include your own class features.
}
Description:In above Example,if we create the object of student class then we can easily access both class member data.
38) Is inheritance is transitive in nature ?
No.
39) Is this is valid or invalid which are given below ?
class x : y
{
....................
}
class y : z
{
....................
}
class z : x
{
....................
}
40) Is this is valid or invalid which are given below ?
class x
{
class y:x
{
..........................
}
..........................
}
Ans.It is valid because class does not dependent on the classes that are enclosed.
41) What are the properties of inheritance in c#?
- A derived class extends its direct base class.
- Derived class can not change or remove the definition of an inherited member.
- Constructors and destructors are not inherited.
- Private member of base class can not inherited in child class(derived class).
- An instance of a class contains a copy of all instance fields declared in the class and its base class.
- A derived class can override an inherited member.
- An declared class can hide an inherited members.
42) What do you mean by visibility control in c#?
In c# ,four types of accessibility modifier,which may be applied to classes and members to specify their level of visibility.
- public
- private
- protected
- Internal
If we do not explicitly set any modifier with the class then it will be By default"Internal"
Internal classes are accessible within the same program assembly and not accessible from outside the assembly.
More Details...
44) Can we access the all member of base class from derived class?
Yes --> if base class member are public.
No ---> if base class member are private.
45) Can we access the class member if class is private?
No.
46) Can we access the class from outside if class is public and data members are public?
No.
47) What is the accessibility constraints in c#?
- An accessibility domain of a member is never larger than of the class.
Ex.
class x
{
private class y
{
public int a;
}
}
we can not access the public data 'a' from the outside the class y.
- All base class accessibility must be at least accessible as derived class itself.
Ex.
class x
{
.....................
}
class y :x
{
......................
}
It is illegal because x is internal ,we can not access the internal class from the derived class.
- The return type of method must be at least as accessible as method itself.
EX.
class x
{
......................
}
public class y
{
x method()
{
.....................//accessible
}
internal x method()
..................//accessible
}
public A method ()
{
.....................//not accessible because public is higher than internal
}
Note:- A Method can not have an accessibility level higher than that of its return type.
48) How can access the base class constructor from the derived class constructor?
We can access the base class constructor using base keyword from the derived class constructor.
Ex.
using system;
class student
{
public int a;
public int b;
public student (int p,int q) //base constructor
{
a=p;
b=q;
}
public int calculate()
{
return(a*b);
}
}
class Teacher:student //inheriting student
{
public teacher(int x,int y,int z):base(p,q)
{
int m=z;
}
public int display()
{
return(m*a*b);
}
}
public static void main()
{
Teacher t =new Teacher(15,10,5);
int area = student.show(); //base class method call
int volume = student.display(); //derived class method call
console.WriteLine("Area="+area);
console.WriteLine("Volume="+volume);
console.ReadLine();
}
49) Can we use base keyword instead of constructor logic?
Yes,We use base keyword constructor as well as any sub class to access a public or protected member defined in a parent class.
Ex.
In above example ,we can access the member of base class in child class as:
base a = 20;
base b = 30;
int area = base.show()
50) What is order of execution of constructor in below example?
A() class A Base class
B() class B Derived class
c() class c derived class
51) What is method overloading in c#?
More Details....
52) What is method Hiding in c#?
More Details....
53) What is abstract class and abstract method in c#?
More Details....
54) What is sealed class in c#?
A class that can not be subclassed ,is called sealed class.
55) Can we inherit the sealed class in c#?
No.
56) What is the use of sealed class in c#?
- Sealed class is used to prevent any unwanted extensions to the class.led class allows the compiler to perform some
- Sealed class allows the compiler to perform some optimizations when a method of a sealed class is invoked.
A sealed Method is used to override an inherited virtual method with the same signature.
Ex.
{
public virtual void show()
{
console.WriteLine("Hello");
}
}
class teacher :student
(
public sealed override void show()
{
console.writeLine("Bye");
}
}
Note:- Any derived class of 'teacher' can not further override the method show().
58) What are the types of polymorphism in c#?
- Operation polymorphism
- Inclusion Polymorphism
Operation polymorphism is implemented with the help of overloaded methods and operators.
- Method overloading
- Operator overloading
Method overloading and operator overloading is known as compiler binding or early binding or static binding.This also called compiler time polymorphism.
60) What is Inclusion polymorphism ?
Inclusion polymorphism is implemented in the concept of method overriding.In method overriding we use virtual keyword.In method overriding object of class bind at run time,so it is called run time binding or late binding.It is also known as run time polymorphism.61) What is an Identifier ?
62) What is Ad -hoc -polymorphism in c# ?
Ad-hoc-polymorphism is another name of overloading.
63) What are benefits and goals of objected-oriented programming ?
- Reliable
- Maintainable
- Extendable
- Natural
- Reusable
- Time saving
0 comments:
Post a Comment