Classes and Objects in Java
Class:
To understand classes and objects in
We divide people depending upon there professions. We
teachers, engineers and all those kinds of professions.
So basically a class is a classification of a certain type of objects
In a similar way, we can also classify certain things in different groups
while using them in Java.
If you want to learn classes and objects in Java, So let’s take this example of the class. let’s consider, basically
We divide people depending upon there professions. understand how object-oriented programming works.
let’s go ahead and create a new class.
To create a class you should type public or private keyword
and then you must type a class keyword and then type your desired
class name.
Note: You must type the first word of the class name in Capital letter.
Syntax to create a class:
If you want to create a class then you have to write a public or private keyword, class keyword, Class Name, and two middle
brackets.
For Example:
If I want to create class named Doctor then I will type…..
public class Doctor{
}
A class contains the following two things.
1.Data
2.Functions
Data: data means variables
Functions: Functions means that you are creating inside the class.
When you want to create a class in NetBeans then you have to click
on your project and then click on Source packages.
After clicking on source packages right click on the package if
haven’t created package yet first create your package by clicking
on the default package.
Right click on the package then click on new and then
So if you are using IntelliJ Idea then you must go to your project
click on it and under your project you will see src folder
right click on that folder and then new and then select a new
java Class.Give any name to your class so your class will be created
.
Objects in Java:
Objects is created in Main class following is the syntax to create an object
for any class.
classname objectname = new classname()
e.g Doctor patient1 = new Doctor()
If you found this article useful share it with your friends to motivate me to write such type of articles
See Also:
Follow me on facebook for more