Objected Oriented Programming Concepts
OOPS is completely
based on the concepts that are applicable in our day today life so that it
is
named as Object Oriented Programming System.
Vegetables onion = Vegetables();
String address;
String Gender;
Integer age;
Vegetables vName;
//etc....
String name;
String address;
String Gender;
Integer age;
Vegetables vName;
Bank nBank;
AtmMoney atm;
//etc....
}
Object Oriented with real time example:-
As u know Object is the instance of class, Let consider ‘U’
(Sagar) as object where as ‘U’ belongs to the ‘Human being’ category and Every
Human being has so many properties Name, Address and Gender etc..
Convert the same in Java
programming language.
Class HumanBeing() {
String name;
String address;
String Gender;
Integer age;
String name;
String address;
String Gender;
Integer age;
}
HumanBeing Sagar = new HumanBeing();
HumanBeing Sagar = new HumanBeing();
Next consider relation and interaction between different
classes and Objects.
Scenario 1: Ur mom
told u brings ‘Onion’ from Vegetables market.
Where U and Mom are the Objects belongs to the ‘HumanBeing’ Class and
‘Vegetables’ Market is another class have properties vegetable name, price,
quantity and quality.
Java:
Java:
Class HumanBeing() {
String name;
String address;
String Gender;
Integer age;
//etc....
}
HumanBeing U/mom = new HumanBeing();}
Class Vegetables() {
String vName;
String quality;
String quantity;
String marketAddress;
Integer price;
//etc....
}Vegetables onion = Vegetables();
Scenario 2: Before ur mom told u about the vegetables U
and ur mom should know the Onion details how it looks, price and types of
quality, this creates relation between Humanbeing and Vegetables class.
Java:
Class HumanBeing() {
String name;String address;
String Gender;
Integer age;
Vegetables vName;
//etc....
}
HumanBeing U/mom = new HumanBeing();
Same real
time concepts oops is using and consider to go to market u should know the
where market is and also should have money to buy. So lets make little complex if u don’t have money or doesn’t known the
market address then first u have find
out the address of the market by known resources
(interaction with other classes), after that u have to go to get money from Bank,
ATM or ur Father these are different level of interaction and commonsense in
real life . So that oops used so many properties
and concepts like inheritance, Overloading etc to define real time interaction
and relation.
Java:
Class HumanBeing() {Java:
String name;
String address;
String Gender;
Integer age;
Vegetables vName;
Bank nBank;
AtmMoney atm;
//etc....
}
HumanBeing U = new HumanBeing();
Class Bank/AtmMoney(){
String bName;
String bAddress;
//etc....String bName;
String bAddress;
}
Comments
Post a Comment