Menu

Java - OOP, Class, Data Types
📰

Java - OOP, Class, Data Types

DEV Community: java·Gowtham·23 days ago
#E4N6ifXa
#devtojava#devto#dev#class#name
Reading 0:00
15s threshold

1.OOP in Java:

OOP stands for Object-Oriented Programming.

It is a programming approach based on classes and objects. It helps us organize code, reuse functionality, and manage complex programs.

Java supports four main OOP principles:

Encapsulation : Combining data and methods in a class and controlling access to the data.

Inheritance : Creating a new class based on an existing class.

Polymorphism : Allowing the same interface or method name to have different behaviors.

Abstraction : Hiding implementation details and exposing essential functionality.

2.Class in Java:

A class is a blueprint for creating objects.

It defines the data and behaviors that its objects can have.

Example

`class Student {

String name = "Gowtham";

int age = 20;

void display() { System.out.println(name); System.out.println(age); }

Enter fullscreen mode

Exit fullscreen mode

}

`In this example:

Student is the class name.

name and age are instance variables.

display() is a method.

We can create an object of the class…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.