As the name suggests, Object-Oriented Programming or OOPs refers to languages that use objects in programming, they use objects as a primary source to implement what is to happen in the code. Objects are seen by the viewer or user, performing tasks assigned by you.
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.
- Classes and Objects
- Access Modifiers
- Basic OOPs Concepts [Inheritance,Abstraction,Encapsulation and Polymorphism]
- Interface
- 'this' Reference Variable
A class in Java is a set of objects which shares common characteristics/ behavior and common properties/ attributes. It is a user-defined blueprint or prototype from which objects are created. For example, Student is a class while a particular student named Ravi is an object.
- Class is not a real-world entity. It is just a template or blueprint or prototype from which objects are created.
- Class does not occupy memory.
- Class is a group of variables of different data types and a group of methods.
- Classes in JAVA contains Data Member,Methods,Constructors,Nested Classes and Interface.
- Modifier -> A class can be public or has default access modifier.
- Class Keyword -> For creating a class we uses the class keyword.
- Class name -> The class name is been created by following the same rules we used to follow while creating a variable.
- SuperClass -> The name of the parent class is generally consider as SuperClass and the one written after extends keyword.
- Interfaces -> It is a kind of list of interfaces implemented or initiated by the class, preceded by the Interface keyword and most interesting fact here is a single class can implement more than one keyword.
- Body -> The Whole Block of code surrounded or covered by Curly Braces {}.
public class class_name{
// data members
int number;
// methods
public void display(){
System.out.println("Display method of the class");
}
// constructors
class_name(){
System.out.println("Class Object initiated");
}
}
An object in Java is a basic unit of Object-Oriented Programming and represents real-life entities. Objects are the instances of a class that are created to use the attributes and methods of a class. A typical Java program creates many objects, which as you know, interact by invoking methods.
- State -> Used for representing by attributes of it and also for reflecting its properties.
- Behaviour -> Represented by the Methods and its reflects the response of it with other object.
- Identity -> Used for giving a unique name to it and enables to interact with another Object.
class first{
int age;
public void display(){
System.out.println("Displayed some Information");
}
}
class Sample{
public static void main(String[] args){
first obj_name = new first(); // Object Created
obj_name.display();
}
}