Introduction To Class & Objects
Java is an
object-oriented programming language. Everything in Java is associated with
classes and objects, along with its attributes and methods.
A Class is like an object constructor, treated
as a “blueprint” for creating objects.
Syntax to create a new object is:
objects of one class can be created as shown below:
public class MyClass
Accessing Object from Different Class
An Object of a class can be accessed in another class.
Variables within the class can be accessed through Objects as shown below:
Example 2: Change X value from 60 to 16.
Example 3: To avoid the override of existing value, the attribute has to be declared as ‘Final’.
values can be changed in one object, without affecting the attribute values of