what do you mean by class & object? give a least 10 real life example of each
Answers
Answer:
class-
a class is basically user-defined data types which act as a template for creating objects of the identical type. It represents the common properties and actions (functions) of an object. In other words, a class can also be defined as "a class is a group of objects which are common to all objects of one type".
object-
An object in Java is any real-world things that have properties and actions. In other words, an entity that has state and behavior is known as an object. Here, State represents the properties and Behaviour represents the actions or functionality.
Explanation:
Real time example of Object-
Realtime example 1:
We are taking the example "person". A person has three characteristics: Identity (name), State (properties), and behavior (actions or functionality). Consider the below image.
The actions or behavior of the person may be "eat, sleep, walk, play, and study". These actions is represented in Java like this: eat(), sleep(), walk(), play(), and study(). These are called methods.
Realtime example 2:
Another example we can take "Pencil". A pencil is an object. Its name is Natraj. State: the color is black. Behavior: It is used to write so writing is behavior.
Real time example of class-
Realtime example 1:
Let us consider two objects Samsung Galaxy S4 and iPhone. Suppose Samsung Galaxy S4 have some properties like width="6.98 cms", height="13.6 cm", OS="Android", brand="Samsung", price="1000$" and Actions are call(), sendMessage(), browser(), share().
Now, suppose iPhone has some properties such as width="5.86 cm", height="12.3 cms", OS="iOS", brand="Apple", price="1200$" and actions are call(), sendMessage(), browse(), share().
Realtime example 2:
Consider two objects one boy and one girl. The boy has some properties like hairColor="black", eyeColor="black", skinColor="Fair", height="5.10 inch", weight="65 kg" and actions are read(), play(), sleep(), walk().
Now, The girl has some properties like hairColor="Brown", eyeColor="brown", skinColor="milky white", height="5.4 inch", weight="50 kg" and actions are read(), play(), sleep(), walk(). but the type of both is the same. i,e Person. So the class name is 'Person'.
Explanation:
A class is used in object-oriented programming to describe one or more objects. It serves as a template for creating, or instantiating, specific objects within a program.
An object is nothing but a self-contained component which consists of methods and properties to make a particular type of data useful. Object determines the behavior of the class
For example:
- in real life, a car is an object. The car has attributes, such as weight and color, and methods, such as drive and brake.
- We are taking the example "person". A person has three characteristics: Identity (name), State (properties), and behavior (actions or functionality).
- A pencil is an object. Its name is Natraj. State: the color is black. Behavior: It is used to write so writing is behavior.
- The boy has some properties like hairColor="black", eyeColor="black", skinColor="Fair".
- Class - Dogs , Data members or objects- size, age, color, breed, etc.
#learn more :
https://brainly.in/question/11316879