Java is one of the most popular programming languages used for developing various applications. One of the key concepts in Java is object-oriented programming, which allows developers to create modular, reusable, and maintainable code. Class and objects are at the heart of object-oriented programming in Java.
In this article, we will explore some common practices and questions related to classes and objects in Java. We will cover topics such as creating classes, defining attributes and methods, instantiating objects, accessing class members, and more. By the end of this article, you should have a solid understanding of the fundamentals of class and objects in Java, and be able to apply these concepts to your own programming projects.
Question : 1 Define a class CARRENTAL with the following details :
|
||||||||||||
Answer : Click here to view answer. | ||||||||||||
Question : 2. Define a class SUPPLY in Java with the following descriptions :
|
||||||||||||
Answer : Click here to view answer. | ||||||||||||
Question : 3. Define a class Candidate with the following description
|
||||||||||||
Answer : Click here to view answer. | ||||||||||||
Question : 4. Define a class Resort with the following description:
|
||||||||||||
Answer : Click here to view answer. | ||||||||||||
Question : 5. Create a class Bank with the following Menu :
|
||||||||||||
Answer : Click here to view answer. | ||||||||||||
Question : 6. Define a class Garments with the following description :
|
||||||||||||
Answer : Click here to view answer. | ||||||||||||
Question : 7. Define a class Tour with the following description:
For each Adult
For each kid the above Fare will be 50% of the fare mentioned in the above table.
|
||||||||||||
Answer : Click here to view answer. | ||||||||||||
Question 8. Define a class employee with the following specification :
|
||||||||||||
Answer : Click here to view answer. | ||||||||||||
Question : 9. Write a program to print the area of two rectangles having sides (4,5) and (5,8) respectively by creating a class named ‘Rectangle’ with a method named ‘Area’ which returns the area and length and breadth passed as parameters to its constructor. | ||||||||||||
Answer : Click here to view answer. | ||||||||||||
Question : 10. Create a class employee which accepts name, year of joining, salary and address of three employees . Now display the output as follows:
Answer : Click here to view answer.
|
In conclusion, understanding classes and objects is essential for any Java developer who wants to create efficient and scalable code. In this article, we have explored various practices and questions related to classes and objects in Java. We learned how to create classes, define attributes and methods, instantiate objects, and access class members. We also explored some common mistakes and best practices for writing object-oriented code in Java.
It is important to remember that classes and objects are just one aspect of object-oriented programming in Java. To become a proficient Java developer, you should also familiarize yourself with other object-oriented concepts such as inheritance, polymorphism, and abstraction.
By applying the best practices and principles discussed in this article, you can write efficient, reusable, and scalable code in Java. With practice and experience, you can become a skilled Java developer and build robust applications that meet the demands of today’s digital landscape.