0% found this document useful (0 votes)
13 views5 pages

Oops 1

Uploaded by

bgmiv31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Oops 1

Uploaded by

bgmiv31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Object Oriented Programming Structure:

=================================
Object-oriented programming (OOP) is a programming method that represents the concept of
"objects" that have data fields (attributes that describe the object) and associated procedures/functions
known as methods.

Class and object


============
Class :
-----------
* Class is a collection of objects.
* Class is a template of an object.
* A class is a blue print from which individual objects are created.
* A class is a programming structure of an object contains member variables and member functions
* It is a userdefined datatype.

Syntax:
class classname
{
member variable declarations;
member function definition;
}

Note;
Member of classes has protected access specifier in default.

Object :
~~~~~~
* An object is an instance(Example) of a class.
Object creation = instanciation
* Objects have states and behaviors.
* Class doesn't have memory, but the object has a memory.

It is a reference type variable.


Syntax:
classname obj=new classname();
Ex:
student s = new student();

Access Specifier :
--------------------
1) private
Variables and functions can be accessed only inside the class.

2) public
Variables and functions can be accessed from anywhere.
3)protected
Variables and functions can be accessed from inside the class and also from the child class.

class bank
{
private int ac_no;
private string name;
p-rivate float balance;

public void read()


{....
}
}

bank b1,b2,b3;
b1=new bank();
b2=new bank();
b3=new bank();

Benefits of OOPS:
1) Data Hiding : Declaring a members of the class with Private keyword established the data hiding.
It is used to hide internal object details to other classes.
Ex:
class bank
{
private int acno;
private int balance;
}
2) Data Encapsulation : Encapsulation is a way of organizing data and methods into a structure by
concealing the the way the object is implemented, i.e. preventing access to data by any means
other than those specified.
Ex:
class book
{
String bname="ponniyin selvan",author="kalki",subj="novel";
int price=1200;
}
book b= new book();
share(b);
3) Data Abstraction :
• Focus on the meaning of the operations (behavior), to avoid over-specification.
• The representation details are confined to only a small set of procedures that create and manipulate
data, and all other access is indirectly via only these procedures.
Ex:
class student
{
String sname; //member variable
int m[]=new int[5];
int tot,avg;
}
4) Polymorphism
5) Inheritance: Creating a class from another class.

Example :
import java.util.*;

class student

Scanner s= new Scanner(System.in);

String sname,result;

int m1,m2,m3,m4,m5,tot;

float avg;

void read()

System.out.print("\nEnter student name : ");

sname = s.nextLine();

System.out.println("Enter 5 marks : ");

m1 = s.nextInt();

m2 = s.nextInt();

m3 = s.nextInt();

m4 = s.nextInt();

m5 = s.nextInt();

void calculation()

tot = m1+m2+m3+m4+m5;

avg = tot/5;
if(m1>=35 && m2>=35 && m3>=35 && m4>=35 && m5>=35)

result="Pass";

else

result="Fail";

void display()

System.out.println("\nStudentName : " + sname);

System.out.println("Total : " + tot);

System.out.println("Average : " + avg);

System.out.println("Result : " + result);

public static void main(String arg[])

student s1,s2,s3;

s1= new student(); //object creation( instantiation) -- Memory creation

s2=new student();

s3= new student();

s1.read();

s2.read();

s3.read();

s1.calculation();

s2.calculation();
s3.calculation();

s1.display();

s2.display();

s3.display();

You might also like