xxxxxxxxxx
====The general view of Object Oriented Programming====
Object-Oriented Programming (OOP) is the term used to describe a programming
approach based on objects and classes. The object-oriented paradigm allows us
to organise software as a collection of objects that consist of both data and
behaviour. This is in contrast to conventional functional programming practice
that only loosely connects data and behaviour
xxxxxxxxxx
-----What Is an Object in Programming?----
Object-oriented programming, or OOP, is an approach to problem solving
where all computations are carried out using objects. An object is a
component of a program that knows how to perform certain actions and how
to interact with other elements of the program. Objects are the basic units
of object-oriented programming. A simple example of an object would be a
person. Logically, you would expect a person to have a name. This would be
considered a property of the person. You could also expect a person to be able
to do something, such as walking or driving. This would be considered a method
of the person.
xxxxxxxxxx
Object Oriented Programming or OOP is a programming paradigm
(style of writing code). In OOP is based on concept of "Objects"
to create objects we define classes (blueprint of objects).
OOP is preferred in big projects where multiple developers are working
on same project, as OOP design provides a coding style which is easy
to understand, contribute, safe to share and modify.
Object-oriented programming, also referred to as OOP, is a programming paradigm that includes, or relies, on the concept of classes and objects.
The basic entities in object-oriented programming are classes and objects.
Programming isn’t much use if you can’t model real-world scenarios using code, right? This is where object-oriented programming comes.
The basic idea of OOP is to divide a sophisticated program into a number of objects that talk to each other.
Objects in a program frequently represent real-world objects.
It is also possible for objects to serve application logic and have no direct, real-world parallels. They manage things like authentication, templating, request handling, or any of the other myriad features needed for a practical application.
xxxxxxxxxx
class Alien { // Name of the class
// The constructor method will take a number of parameters and assign those parameters as properties to the created object.
constructor (name, phrase) {
this.name = name
this.phrase = phrase
this.species = "alien"
}
// These will be the object's methods.
fly = () => console.log("Zzzzzziiiiiinnnnnggggg!!")
sayPhrase = () => console.log(this.phrase)
}
class Bug {
constructor (name, phrase) {
this.name = name
this.phrase = phrase
this.species = "bug"
}
hide = () => console.log("You can't catch me now!")
sayPhrase = () => console.log(this.phrase)
}
class Robot {
constructor (name, phrase) {
this.name = name
this.phrase = phrase
this.species = "robot"
}
transform = () => console.log("Optimus prime!")
sayPhrase = () => console.log(this.phrase)
}
xxxxxxxxxx
// Class Declaration
public class Dog
{
// Instance Variables
String name;
String breed;
int age;
String color;
// Constructor Declaration of Class
public Dog(String name, String breed,
int age, String color)
{
this.name = name;
this.breed = breed;
this.age = age;
this.color = color;
}
// method 1
public String getName()
{
return name;
}
// method 2
public String getBreed()
{
return breed;
}
// method 3
public int getAge()
{
return age;
}
// method 4
public String getColor()
{
return color;
}
@Override
public String toString()
{
return("Hi my name is "+ this.getName()+
".\nMy breed,age and color are " +
this.getBreed()+"," + this.getAge()+
","+ this.getColor());
}
public static void main(String[] args)
{
Dog tuffy = new Dog("tuffy","papillon", 5, "white");
System.out.println(tuffy.toString());
}
}