Oops by Kannababu
Oops by Kannababu
Oops by Kannababu
OOPS is a concept, which is used to write the programs by using classes and
objects
Principles of OOPS :-
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
Any Language that supports the above 4 principles then that language is called
as Object Oriented Programming Language
Any Language that does not support tleast one among the above 4 principles,
then that language is called as Object Oriented Based Programming Language
Ex:- Javascript,vbscript,C++
State,Behavior
state:- variable
Behavior:- method
------------------------------------------------------------------------------------------
Game:-
------------------------------------------------------------------------------------------
Ex:-
------------------------------------------------------------------------------------------
{ { {
------------------------------------------------------------------------------------------
variable:-
int x;
int x=9;
int x;
x=5;
1. static variable
2. instance variable
3. Methodparameters
4. Local Variable
static variable must declare inside the class and outside the method
class A
instance variable must declare inside the class and outside the method
------------------------------------------------------------------------------------------
class Student
int sno;
void SetStudent()
Local variable:- The variable that was declared inside the method or within the
block is called as Local variable
class A
int x=5;
class A
------------------------------------------------------------------------------------------
class Student
int sno;
string sname;
int age;
int total=m1+m2+m3;
classname:- Student
Methodparameters:- m1,m2,m3
------------------------------------------------------------------------------------------
using System;
class Student
void CalPercentage()
void GetGrade()
------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
class Employee
int eno;
string ename;
double bsal;
void CalDa()
double da=0.2*bsal;
void CalHra()
double hra=0.4*bsal;
Employee:- classname
------------------------------------------------------------------------------------------
1. What is a variable?
datatype varname;
by using variablename
1. static variable
2. instance variable
3. local variable
4. method parameters
1. inside the class and outside the method with static keyword
2. inside the class and outside the method without static keyword
int x;
int x=5;
int x;
x=5;
class Student
int sno;
string sname;
The memory for the static variable will allocate only once
class Student
------------------------------------------------------------------------------------------
The variable that was declared inside the method or within the block is called
as Localvariable
class A
Ex:-
class A
if(10>4)
int x=5;
11. What is the difference between method parameters and local variables?
class A
int z=+y;
heap
stack
Stack
------------------------------------------------------------------------------------------
The memory for the local variable will allocate when we call the method
once when the method execution is completed then local variable will be
destroyed
class Student
int sno;
void Set()
int m1=90;
sno=10;
void Get()
Console.WriteLine(sno);
Console.WriteLine(m1); Error
------------------------------------------------------------------------------------------
class A
static int x;
void Set()
x=5;
void Get()
C.WL(x);
if the value is common for all the users then make the variable as static
if the value is unique for the user then declare the variable as instance
if the value is used only for one time within the method then declare the
variable as
local
------------------------------------------------------------------------------------------
instance variables
Error
No
No
No
32. How many times memory was allocated for static variable
33. How many times memory was allocated for instance variable
------------------------------------------------------------------------------------------
No
No
NO
37. The variables that were created inside static method are static?
38. The variables that were created inside instance method are instance?
class A
------------------------------------------------------------------------------------------