Summary JavaScript - CS6401 (Cs)
[29/06, 2:29 pm] Akash: Object-Oriented Programming Principles (OOPS) Creating Object and Class Blueprint Object: An individual entity that has state and behavior. An instance of a class. Class: A blueprint for creating objects. Contains a set of properties (attributes) and methods (functions). Class and Object in Java In Java, a class is defined using the class keyword. To create an object, use the new keyword followed by the class name and parentheses (). Example: class MyClass { // properties and methods } MyClass myObj = new MyClass(); myObj is an object of the class MyClass. To access the properties and methods of an object, use the dot (.) operator. Example: myOProperty = "value"; myOMethod(); Additional notes: Objects can be thought of as "nouns" and classes as "blueprints for nouns". Objects have their own unique state (properties) and behavior (methods). Classes define the common behavior and state for objects of the same type. References: Java Classes and Objects (The Java Tutorials Learning the Java Language Classes and Objects) Java: Understanding Classes and Objects [29/06, 2:29 pm] Akash: Class and Object in Java Creating Object and Class Blueprint In Java, a class is a blueprint or template that defines the properties and behaviors of an object. An object is an instance of a class. It has state and behavior. Here's how you can create a class and an object in Java: Creating a class: Define a class by using the keyword class. Define the properties of the class using variables. Define the behaviors of the class using methods. Example: public class Car { String color; int numberOfDoors; void start() { // code here } void stop() { // code here } } Creating an object: Declare an object by using the name of the class followed by the object name. Create the object by using the new keyword and the constructor of the class. Access the properties and behaviors of the object using the dot operator. Example: Car myCar = new Car(); myC = "red"; myCrOfDoors = 4; myC(); myC(); Object-Oriented Programming Principles Java is an object-oriented programming (OOP) language, which is based on the following principles: Encapsulation: Encapsulation is the practice of keeping the fields within a class private, so they can only be accessed and modified through methods. Inheritance: Inheritance is the ability of a class to inherit the properties and methods of another class. Polymorphism: Polymorphism is the ability of an object to take on many forms. This means that a single variable can refer to objects of different classes. Abstraction: Abstraction is the process of hiding the implementation details of a class and only exposing the necessary functionality to the user. By following these principles, you can create programs that are more organized, reusable, and easier to maintain.
Connected book
- Unknown
- 9780538468138
- 5
Written for
- Institution
- Anna University
- Course
- CS6401 (CS)
Document information
- Summarized whole book?
- No
- Which chapters are summarized?
- Unknown
- Uploaded on
- June 29, 2024
- Number of pages
- 5
- Written in
- 2023/2024
- Type
- SUMMARY
Subjects
-
js javascript
-
java story