Information on Java please explain these concepts no need to
Information on Java
please explain these concepts no need to program anything just a quick summary
CLASSES -- Have not learned them yet and have these questions
What is a class and why are they important ?
Explain the relationship betweeen a class and an object .
Discuss the term HAS-A
Discuss the term instance Variable.
What is a constructor method
How do you create a constructor method ?
Discuss encapsulation
Discuss Data Hiding.
Solution
Class and importance of class:
Relationship between a class and an object:
HAS-A:
Has-A means an instance of one class “has a” reference to an instance of another class or another instance of similar class and it is also known as composition or aggregation.
Instance Variable:
Instance variables are declared in a class, but outside a method, constructor or any block. These are created when an object is created with the use of the keyword new and destroyed at what time the object is destroyed.
Constructor method:
To initialize the object we can use constructor method and it is invoked at the time of object creation.
Creation of constructor:
Constructor name must be same as its class name and it must have no explicit return type. If there is no parameters is known as default constructor.
Syntax: <class_name>()
{
}
Encapsulation:
Encapsulation in is a wrapping the data (variables) and code acting on the data (methods) jointly as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only during the methods of their current class. Encapsulation is also known as Data hiding.
