Assignment 2 Class 9
Assignment 2 Class 9
(6) Applets: These are the Java programs that are executed in a web browser like Microsoft
Internet Explorer: They can only access the resources of a remote system.
Scanned by CamScanner
9. What does a class need to define, when used as a data type in a Java project?
values and functions or methods that
Ans. A class needs to define data variables to store the data
variables are called
define the process to be performed on the objects of the class. These data
member variables and the methods are called member functions or member methods.
10. How does a class implenment data abstraction and encapsulation features of OOP?
Ans. A class defines the data variables (called member variables) and the methods/functions (callcd
member functions) common to a set of objects of the class. In other words we can say that these
members varíables and functions are encapsulated into a single unit called class. This encapsulation
leads to abstraction (hiding). Due to this encapsulation, users know how to access the encapsulated
code no matter what the implementation details are.
11. Is it possible that an object has more than one abstractions? Explain with examples.
Ans. Yes, it is possible for an object to have more than one abstraction. This can be understood from an
example of an employee. The attributes and methods for the personal details of an employec can
be wrapped up in a class named "Personal" and the attributes and methods related to details of
the employees salary can be wrapped up in another class named
"PaySlip". Thus, the
same
can possess multiple abstractions by encapsulating relative attributes and methods in more than
object
one classes. Similarly, an account holder can have the personal details in one class say-AccHolder
nd the details of the account in another class say-AccBalance.
12. How to create an object in Java?
Ans. An object is created from a class. In Java, the new key word is used to create new object.
For example: progl objl= new prog1()
Where progl is the class, objl is the newly created object's name and prog1() is the constructor
of the class.
13 What declarations are required for every Java application?
Ans. A class and the main()
method declarations.
aWhy object is called an instance
an
of a
class?
2010
Ans. A class encapsulates the data members and member functions. It is used to create an object. A
class is an object factory. Hence, an object is called an instance of a class.
I5.) Why is a class known as composite data type?
Ans. Class is called a composite data type because it binds
types together as a single data type.
up (encapsulates) one or more primitive
e.g, class Abc {
int x,
float y;