Oops by Kannababu

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

NOTES CREATED BY – RAHUL KHARAT

OOPS BY KANNABABU SIR

OOPS :- Object Oriented Programming System

OOPS is a concept, which is used to write the programs by using classes and
objects

OOPS was developed by Grady Booch.

Programming Languages are developed by following the principles of OOPS.

- C#.net Java Python Typescript

Principles of OOPS :-

1. Abstraction

2. Encapsulation

3. Inheritance

4. Polymorphism

Q)what is Object Oriented Programming Language?

Any Language that supports the above 4 principles then that language is called
as Object Oriented Programming Language

Ex:- C#.net,Java,Python,Typescript etc...

Q)what is Object Based 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

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 1


NOTES CREATED BY – RAHUL KHARAT

variable:- variable is the name given for a particular memory location

purpose of variable is to store value

Method:- Method is subprogram used to perform a specific operation

Game:-

identify variables and methods:-

Q)developing an appn for a particular college to maintain the student


details,facdetails,course, dept details?

identify the variables and methods?

Sno courseid SetCredits() dname

eno SetStudent() ename GetStudent()

sal CalTotal() designation CalDa()

qualification CalHra() emailid CalTsal()

sname coursename GetDname() age

credits GetCname() gender dno phoneno

------------------------------------------------------------------------------------------

Abstraction:-it is a process of getting the required data and hiding unnecessary


data

Ex:-

identify the student variables and student methods

identify the emp variables and emp methods

Encaspulation:- it is a process of Binding or Wrapping or Grouping of state and


behavior in a single container

in object oriented programming Languages like C#.net ,Java,Typescript,Python


etc.. we can achive Encaspulation by using class.

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 2


NOTES CREATED BY – RAHUL KHARAT

class Student class Employee class Course

{ { {

int sno; int eno; int courseid;

string sname; string ename; string cname;

int age; double bsal; int credits;

string gender; double da; void SetCourse()

string emailid; double hra; {

int m1,m2,m3; double tsal; }

void SetStudent() {} void CalDa(){} void GetCourse(){}

void CalTotal(){} void CalHra(){}

------------------------------------------------------------------------------------------

class:-class is userdefined Referencetype Datatype which consists of variables


and methods

in object oriented programming languages like C#.net,java,pythion we can achive


Encapsulation by using class

variable:-

variable is the name given for a particular memory location

Q)what is the purpose of variable?

The purpose of variable is to store the value

Q)what is variable declaration?

declaring the variable without assigning the value

int x;

Q)what is variable initialization?

assigning the value to the variable at the time of declaration

int x=9;

SathyaTechnologies | KannababuBanna.Net Real time Expert 3


NOTES CREATED BY – RAHUL KHARAT

Q)what is variable assignment?

assigning the value to the variable after declaration

int x;

x=5;

Different types of variables:-

1. static variable

2. instance variable

3. Methodparameters

4. Local Variable

static variable :- static variable must declare with static keyword

static variable must declare inside the class and outside the method

class A

static string collegename;

static void Main()

instance variable:- instance variable is the instance member of the class

instance variable must declare inside the class and outside the method

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 4


NOTES CREATED BY – RAHUL KHARAT

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

static void Main()

int x=5;

MethodParameters:- The variables that was declared within the method


paranthesis are called as MethodParameters

class A

void Add(int x,int y) {

x,y are called as methodparameters

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 5


NOTES CREATED BY – RAHUL KHARAT

class Student

static string cname="sathyatechnologies";

int sno;

string sname;

int age;

void CalTotalMarks(int m1,int m2,int m3)

int total=m1+m2+m3;

In the above program :-

classname:- Student

static variables:- cname

instance variable:- sno,sname,age

Local variables :- total

Methodparameters:- m1,m2,m3

------------------------------------------------------------------------------------------

using System;

class Student

static string collegename;

static string collegeaddress;

int sno; string sname; int total;

SathyaTechnologies | KannababuBanna.Net Real time Expert 6


NOTES CREATED BY – RAHUL KHARAT

void SetStudent(int no,string name)

void CalTotal(int m1,int m2,int m3)

void CalPercentage()

int percentage = total / 3;

void GetGrade()

char grade = 'A';

In the above program :-

classname:- Student static variables:- collegename,collegeaddress

instance variables:- sno,sname,total

Method parametersL:- no,name,m1,m2,m3

Local variables:- percentage,grade

Methodnames:- SetStudent() CalTotal() CalPErcentage() GetGrade()

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 7


NOTES CREATED BY – RAHUL KHARAT

class :- variables and methods

variable:- store the value

method:- perform operation

-----------------------------------------------------------------------------------------

class Employee

static string companyname ;

int eno;

string ename;

double bsal;

void CalDa()

double da=0.2*bsal;

void CalHra()

double hra=0.4*bsal;

In the above program :-

Employee:- classname

companyname:- static variable

eno,ename,bsal:- instance variable. da,hra :- local variable

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 8


NOTES CREATED BY – RAHUL KHARAT

1. What is a variable?

variable is the name given for a particular memory location

2. When should we create a variable?

whenever we want to store any value then we have to create variable

3. How can we edclare a variable?

datatype varname;

4. How to access the value?

by using variablename

int x=10; variable initialization

Console.WriteLine(x); access the variable

5. How many types of variables are there in C#.net?

1. static variable

2. instance variable

3. local variable

4. method parameters

6. What are different places we can create a variable in C#.net?

1. inside the class and outside the method with static keyword

2. inside the class and outside the method without static keyword

3. inside the method

4. within the method paranthesis

7. What is the difference between variable declaration,initialization and


assignment?

variable declaration:- declaring the value without assigning the value

int x;

SathyaTechnologies | KannababuBanna.Net Real time Expert 9


NOTES CREATED BY – RAHUL KHARAT

variable initialization:- assigning the value to the variable at the time of


declaration

int x=5;

variable assignment:- assigning the value to the variable after declaration

int x;

x=5;

8. What are instance variables?

instance variables are the instance members of the class.

a seperate memory is allocated for instance variable whenever a new object is


created for a class.

class Student

int sno;

string sname;

9. What are static variables?

static variable is a statis member of a class

static variable must declare with static keyword

The memory for the static variable will allocate only once

class Student

static string collegename;

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 10


NOTES CREATED BY – RAHUL KHARAT

10. What are local variables?

The variable that was declared inside the method or within the block is called
as Localvariable

Rules to be followed while declaring local variable:-

1. local variable must declare inside the method or block

2. local variable must initialize with some value

3. local variable must not declare as static

4. local variable must not have any accessmodifier

5. The scope of LV is within the block or within the method

class A

static void Main()

int x; invalid Local variable must initialize with some value

int y=20; valid

static int z=23; invalid LV must not be static

public static int a=8;invalid LC must not have access modifiers(public)

Ex:-

class A

static void Main()

if(10>4)

SathyaTechnologies | KannababuBanna.Net Real time Expert 11


NOTES CREATED BY – RAHUL KHARAT

int x=5;

Console.WriteLine(x); Error because LV scope is within the Block

11. What is the difference between method parameters and local variables?

The scope of MethodParameter is more compare with LV

class A

void Add(int x,int y)

int z=+y;

x,y -------> Method Parameters

z -------> Local variable

12. Where the memory is allocated for instance variables?

heap

13. Where the memory is allocated for static variables?

stack

14. Where the memory is allocated for local variables?

Stack

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 12


NOTES CREATED BY – RAHUL KHARAT

17. When the memory is allocated for local variable?

The memory for the local variable will allocate when we call the method

18. When the memory is destroyed for local variable?

once when the method execution is completed then local variable will be
destroyed

19. What is the scope of local variable?

within the block

20. What is the scope of instance variable?

within the class

class Student

int sno;

void Set()

int m1=90;

sno=10;

void Get()

Console.WriteLine(sno);

Console.WriteLine(m1); Error

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 13


NOTES CREATED BY – RAHUL KHARAT

21. What is the scope of static variable?

within the class

class A

static int x;

void Set()

x=5;

void Get()

C.WL(x);

22. When to declare the variable as static?

if the value is common for all the users then make the variable as static

23. When to declare the variable as instance?

if the value is unique for the user then declare the variable as instance

24. When to declare the variable as local?

if the value is used only for one time within the method then declare the
variable as

local

25. What is the life span of static variable?

until the program is live

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 14


NOTES CREATED BY – RAHUL KHARAT

26. What is the lifespan of instance variable?

until the object is live

27. What variables will have default value?

instance variables

28. What are the rules on local variables?

Rules to be followed while creating local variable :-

1. local variable must declare inside the method or block

2. local variable must initialize with some value

3. local variable must not declare as static

4. local variable must not have any accessmodifier

5. The scope of LV is within the block or within the method.

a. If we create a local variable without assigning a value, what is the value


stored?

Error

b. Can we access local variable from other methods?

No

c. Can we access local variable before its declaration statement?

No

31. Can we apply static keyword to a local variable/parameter?

No

32. How many times memory was allocated for static variable

only one time

33. How many times memory was allocated for instance variable

Everytime when a new object is created

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 15


NOTES CREATED BY – RAHUL KHARAT

34. Can we access Local variable outside the method?

No

35. Can we access Local variable without initialization?

No

36. Can we declare local variable as static?

NO

37. The variables that were created inside static method are static?

No, its Local variables

38. The variables that were created inside instance method are instance?

No, its Local variables

class A

static int x; -------------------------- static variable

int y; -------------------------- instance variable

static void Show() -------------------------- static method

void Display() --------------------------- instance method

------------------------------------------------------------------------------------------

SathyaTechnologies | KannababuBanna.Net Real time Expert 16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy