Notebook work - User Defined Methods - Object Oriented Programming - Part I
Notebook work - User Defined Methods - Object Oriented Programming - Part I
statements
return statement
Ans. The statements end with an optional return statement that returns a value back to the
calling method. The return type is the type of the value that the method returns. Example of an
User defined method : Let us write a method that given the length and breadth of a rectangle
as parameters returns the area of the rectangle.
The static method allows us to call this method without an invoking object.
double a = 0;
a = rectangle_area(45.5, 78.5);
}
SQP – 2024-25
Q1. What is meant by Object Oriented Programming in Java? Explain with an example.
Ans. Java is an Object Oriented Programming (OOP) language where a program is a collection of
objects that interact with each other to solve a problem. Each object is an instance of a class.
For example, in a bookstore database application, each book can be an object with attributes
like Title, Author, Publisher, and Price. Actions like displaying details or finding the price can be
performed on these objects.
Q2. What is a class in Java? How are data and method members defined in a class?
Ans. In Java, a class is a logical or physical entity that serves as a blueprint for creating objects.
It contains attributes (data members) and actions (method members).
For example, in the class Book, data members could include title, author, publisher, genre, and
price. Method members could include actions like displaying the book details or getting its
price. These method members can access and modify the data members of the class.
(Please write this above code in the image in the notebook as an example)
Class Design
Q. How is class designed/Explain the structure of a class
Ans. A class in Java begins with the keyword class followed by the name of the class. The
body of the class is enclosed within curly braces. The body contains the definitions of the
data and method members of the class.