Java Classes and Objects (OOP)
Classes and Objects (OOP) in Java
- Class – A class represents a set of objects that share common characteristics and behavior.
- Object – An object is an identifiable entity with some characteristics and behavior.
- Method – Function representing specific behavior of an object.
- Java Byte Code – The Java Byte Code is a machine instruction for a java processor chip called Java Virtual Machine. The Byte Code is independent of the computer system it has to run upon.
- Abstraction – Abstraction refers to the act of representing essential features without showing the background details or explanation.
- Encapsulation – The wrapping up of data and functions(that operate on data) into a single unit (called class) is known as Encapsulation. It is a way to implement data abstraction. Encapsulation hides the details of the implementation of the object.
Question: How do objects encapsulate data and behavior?
Answer: As we know that an object is an identifiable entity with some characteristics, attributes and behavior, the state of object depends upon the values of its attributes at any given point of time. Since state and behavior of objects are interwoven they are said to encapsulate state and behavior.
Question: What do you understand by object factory?
Answer: An object factory is a producer of objects. It accepts some information about how to create an object, such as values depicting its state and then returns an instance of that object.
Question: How can you say that a class is an object factory?
Answer: Basically, the class is an object maker or an object factory. It contains all the statements needed to create an object, its attributes as well as the statements to describe the operations that the object will be able to perform.