OOP's....OOP is a subject, no need to panic
Defination
========
OOP is a programming methodology that helps organize the computer program through the use of inheritance, encapsulation and polymorphism.
OOP was introduced to organize complex programs.
WAY TO OOP(C++ and Java)
=======================
1970 - Dennis Ritchie - C
1979 - Bjarne Stroustrup- C with classes
1983 - Renamed it to C++
But as C++ could not support world wide web(WWW)....(Yeah...the internet u are doing now....ORKUTING...Got IT!!)....something new was required
1991-92 - Oak (sir called it OOOOaaaak, why not oak ,I dont know...)
1995 - Java(Oak renamed with more flexibility)
1. Procedural Programming- code based
2. Object oriented Programming- Data Based
Principal of OOP
===============
1. Encapsulation
2. Inheritance
3. Polymorphism
Encapsulation - Protects the data from unauthorized use. JUST LIKE A CAPSULE
Inheritance - Property by which one objects acquire the properties of other. Like a subclass inherits the properties of superclass.
Polymorphism - In hindi....."Ek naam anek kaam" . Thats what it is....
A feature to be used in general class of actions. The action however depends on the nature of situation.
One example of polymorphism(as given by sir)
------------------------------------------------------
Suppose u are reading a book(most likely a comics) and ur mom calls u to take ur dinner, then what will u do is that u will reading 1 or 2 more pages and then leave for dinner. But just in case it was a Phone call u would have rushed for it, irrespective of the interest you were getting, while you were reading.
GOT MY POINT!!
Data Types
==========
Integer-> long(64), int(32), short(16), byte(8)
Floating-> Float(32), Double(64)
Character-> Char(16)
Boolean-> True, False
Array
=====
type variable-name[]=new type[size]
Ex-
1D array:
int month_days[]=new int[4];
2D array:
int twoD[][]=new int[4][5];
function of new operator
->allocates memory at runtime
->so it is dynamic memory allocation
import java.io.*;
class array{
public static void main(String args[])
{
int month_days[]=new int[4];
month_days[0]=31;
month_days[1]=28;
month_days[2]=31;
month_days[3]=30;
s.o.p("April has"+month_days[4]+month_days[3]+"days");
}
}
public->access specifier
to compile:
c:\javac array.java
to execute
c:\java array
Static methods are executed first at the run time.
No comments:
Post a Comment