Unit-1
JAVA INTRODUCTION
Introduction to object-oriented programming concepts
• What is Object-Oriented programming?
As the name suggests, Object-Oriented Programming refers to languages that
use objects in programming. Object-oriented programming aims to implement
real-world entities like inheritance, hiding, polymorphism, etc in programming.
The main aim of OOP is to bind together the data and the functions that
operate on them so that no other part of the code can access this data except
that function.
• OOPs concepts:-
1. Class
2. Object
3. Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
1.Class
o A class is a user-defined data type.
o It consists of data members and member functions, which can be
accessed by creating an instance of a class.
o It represents the set of properties or methods that are common to all
objects of one type.
o A class is like a blueprint of an object.
o For Example: Consider the Class of Cars. There may be many cars with
different names and brands but all of them will share some common
properties like all of them will have 4 wheels, Speed Limit, Mileage
range, etc. So here, Car is the class, and wheels, speed limits, and
mileage are their properties.
o Syntex : -
, public class main{
int x = 5;
}
2. Object
o It is a basic unit of Object-Oriented Programming and represents the
real-life entities.
o An Object is an instance of a Class.
o When a class is defined, no memory is allocated but when it is
instantiated (an object is created) memory is allocated.
o An object has an identity, state, and behavior.
o Object is a run-time entity.
o An object can represent a person, place, or any other item.
o An object can operate on both data members and member functions.
o For Example: “Dog” is a real-life Object, which has some characteristics
like color, Breed, Bark, Sleep, and Eats.
class Data{
int id;
String name;
}
class student{
public static void main(String args[]){
Data s1=new Data(); //Object
s1.id = 1;
s1.name = "Rahul";
System.out.println(s1.id);
System.out.println(s1.name);
}
JAVA INTRODUCTION
Introduction to object-oriented programming concepts
• What is Object-Oriented programming?
As the name suggests, Object-Oriented Programming refers to languages that
use objects in programming. Object-oriented programming aims to implement
real-world entities like inheritance, hiding, polymorphism, etc in programming.
The main aim of OOP is to bind together the data and the functions that
operate on them so that no other part of the code can access this data except
that function.
• OOPs concepts:-
1. Class
2. Object
3. Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
1.Class
o A class is a user-defined data type.
o It consists of data members and member functions, which can be
accessed by creating an instance of a class.
o It represents the set of properties or methods that are common to all
objects of one type.
o A class is like a blueprint of an object.
o For Example: Consider the Class of Cars. There may be many cars with
different names and brands but all of them will share some common
properties like all of them will have 4 wheels, Speed Limit, Mileage
range, etc. So here, Car is the class, and wheels, speed limits, and
mileage are their properties.
o Syntex : -
, public class main{
int x = 5;
}
2. Object
o It is a basic unit of Object-Oriented Programming and represents the
real-life entities.
o An Object is an instance of a Class.
o When a class is defined, no memory is allocated but when it is
instantiated (an object is created) memory is allocated.
o An object has an identity, state, and behavior.
o Object is a run-time entity.
o An object can represent a person, place, or any other item.
o An object can operate on both data members and member functions.
o For Example: “Dog” is a real-life Object, which has some characteristics
like color, Breed, Bark, Sleep, and Eats.
class Data{
int id;
String name;
}
class student{
public static void main(String args[]){
Data s1=new Data(); //Object
s1.id = 1;
s1.name = "Rahul";
System.out.println(s1.id);
System.out.println(s1.name);
}