Java Programming
This are the basic concept of OOPS.
1. Object
2. Class
3. Data abstraction
4. Data encapsulation
5. Inheritance
6. Polymorphism
7. Dynamic binding
This are the basic concept of OOPS.
1. Object
2. Class
3. Data abstraction
4. Data encapsulation
5. Inheritance
6. Polymorphism
7. Dynamic binding
Java Classes/Objects
Java is an object-oriented programming language.
Everything in Java is associated with classes and objects, along with its attributes and methods. 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.
A Class is like an object constructor, or a "blueprint" for creating objects.
Create a Class
To create a class, use the keyword
Myclass.java
Create an Object
In Java, an object is created from a class. We have already created the class named
MyClass
, so now we can use this to create objects.
To create an object of
MyClass
, specify the class name, followed by the object name, and use the keyword new
:
Example=>
public class Myclass{
int x=10;
public static void main(string [] args){
Myclass myobj=new Myclass();
System.out.println(myobj.x);
}
}
Output : 5
Comments