Opps Unit 1 Oops Unit 1 Notes
Opps Unit 1 Oops Unit 1 Notes
PART· 1
1
UNIT
Introdu ction
Encapsulation, Inheritance, Polymorphism.
Questions-Ans wers
1-1 B (MCA-Sem-2)
6. . of
State refers to the properties
arrays, and other data structures.
1-3 B (MCA-Sem-2)
4.
5.
Introduction
. 1-7 B (MCA·Sein. 2
Object Oriented Progranuning --J 1-8 B (MCA-Sem-2) Introductfo~
derived class, inherits properties a d
4. A child class, also known! as aalso known as a base class or superclan When we write code that works with objects of the "Shape" interface,
behavior from its parent c ass, . . ss. we can call the "draw" method on any object that implements the
d 1•ts own properties and behavior, or overrid interface, regardless of its specific type.
5 The child class canthen a d e
. rt· d behavior of its parent c1ass . 10. Polymorphism allows us to write code that can work with objects of
~~pe~an • . .
, ve have a "Vehicle class with properties such •• different types, without knowing their specific type at compile time.
6 ForexampI e, Ie t ssay, h · h "dri ve ■ and
""
· d •
"make", "mo e1 , an
d "year" as well as be av10r sue as
, 11. This makes the code more flexible, generic, and reusable, and allows us
to write more efficient and maintainable code.
"stop". \
7
_ We can then create child classes such as "Car", "Truck", and "Motorcycle•
that inherit these properties and behavior from ~he "Vehicle" class, but
I
Que 1.11. Is the concept of polymorphism only applicable to object-
also add their own specific properties and behavior. oriented systems ? Explain.
8. Inheritance allows us to reuse code and avoid duplicating code in multiple Answer
classes. 1. Polymorphism is a concept that refers to the ~eloi?jects to take on
It also allows us to create classes that are related to each other in a different forms or behaviors. '),,
9.
hierarchical structure, making the code more organized and easier to 2. It allows different objects to respond to the same meaage or method call
maintain. " . in different ways. ,
3. While polymorphism is most co=only associatl!d with object--0riented
Que 1.10. , What do you mean by polymorphism ? Explain it with
programming languages such as J•Pyfcfioii. and C++, w concept
an example. itself is not limited to these languages ~to:object--0riented systems.
4. Polymorphism can be achieved in. oilier programming paradigms as
Answer
well, such as functional programming or procedural programming.
L Polymorphism refers to the ability of objects to take on different forms
or exhibit different behaviors in different contexts. -,' 5. For example, in functional pl'ogramming, higher--0rder functions can be
use d to achieve polymorphism by allowing functions to-fake other
2. Polymorphism allows us to write code that can work with objects of functions as arlr1J'.llents and return functions as results. ..,
multiple types, without knowing their specific type at compile(time.
6. Therefore, while polymorphism is commomy associated with object-
3. In OOP, polymorphism is achieved through the u se of inheritance and oriented systems, it is not limited to them, and can be adrieved in other
interfaces. programming paradigms as well.
4. When a subclass inherits from a superclass, it can override the methods
of the superclass with its own implementation. Que 1.12.1 Discuss the three OOP principles.in detail.
5. This allows objects of the subclass to behave differently from objects of Answer
the superclass when the same method is called.
The three main OOP prin~' are:
6. Interfaces provide another way to achieve polymorphism.
I. Encapsulation: Refer Q. l .5~P ~ l-4B, Unit-1.
7. An interface ~efines_a set of methods that a class must implement, but 2. Inheritance: Refer Q. 1.9, Page"1-6B, Unit-1.
doe_s not proVIde any 1IDplementation details. This allows multiple classes
· e their own spec1'fi1c
· t erf ace, but provid 3. Polymorphism: Refer Q. 1.10, Page l-7B, Unit-1.
. implement
to . the same m
imp1ementat10n details.
Que i.1s.1 Differentiate between structured approach and object
8.
:::: : : l e i ' considehr a "Shape" interface with a "draw" method. We
c asses sue as "Circle" d "Re h oriented approach.
"Shape" interface and . . an ctangle" that implement t ~
method. th
provide eir own implementations of the "draw
1-9 B (MCA-Sem-2)
Object Oriented Programming
1-lOB (MCA-Sem-2)
Introduction
An ■wer
4. Software reuse is not possible. Reusability is possible. 2. Procedural programming follows! Object-oriented programming
top down approach. follows bottom up approach.
5. Structured de sig n Object or ie nt e d d es ign
programming usually left until programming done 3. There is no access specifier in Object -oriented programming
end phases. concurrently with other phases. procedural programmmg. has access specifiers like private,
public. protectedietc.
6. Structured Design is more It is s ui table for in-house
development. 4. Adding new data and function isl Addin1rnew data and function is
suitable for off-shoring.
not easy. easy.
7. It. shows clear transition from N ot so clear transition from
design to implementation. 5. Procedural programming doesl Object-oriented programming
design to
implementation. not have any proper way for provides data hiding so it is more
I hiding data so it is less secure. I secure.
It is suitable for re a l time It is suitable for most business
I 8.
system, embedded system and applications, game development 6. In pr oc~dural programm ing,! Overloading is possible in object-
projects where objects are not projects, which are expected to ove rloading 1s not possible. oriented program.ming.
t h e most u s efu l lev e l of customize or extended. 7. In procedural In object-oriented
abstraction . programming, function is mo re programming, data is more
9. DFD & E-R diagram model the Class diagr a m , s e qu ence important than data. important than function.
data. diagram, state chart diagram, 8. Pr ocedur a l ~ogramming is Object-orientedprogram.mi.ng is
and use cases all contribute. based on unreal world. based on real world.
10. In this, projects can be ma naged In thi s approach , project s can be 9, Examples : C. FORTRAL'-1 . Pa.scat ! Examples : C++. Java, Python,
easily due to clearly identifi able diffi c ul t to manage due to Basic etc . ( C# etc.
phases. uncertain transitions between
p hases.
P A R T-2
OOP i11 Ja va, Characteristics of Jaua, Tire Java Environment,
Que LJ.C.1 What i1 the difference between Procedure Based J aua Source File Strwcture and CompilatiorL
programming language and Object-Oriented progra01min1
language?
1.
Answer I
OOP is a programming paradigm that organizes code around objects
i. Single inheritance is the most basic type of inheritance in Java
where a child class inherits properties and methods from a sing!;
parent class.
that encapsulate data and behavior.
2. Java is a popular object-oriented programming language that supports ii. In single inheritance only one class extends another class.
the OOP paradigm.
Class A
3. In Java, everything is an object, including primitive data types such as
integers and floating-point numbers.
4. Objects are instances of classes, which define the properties and behaviors
of the objects.
5. Following are the main concepts in OOP in Java :
i. Classes and Objects : A class is a blueprint or template for creating
objects. It defines the properties and behaviors that objects of that 2. Multilevel Inheritance :
class will have. An object is an instance of a class.
i. Multilevel inheritance is when a child ciass inherits from a parent
ii. Encapsulation : Encapsulation is the process of hiding the internal class, and that parent class is also a child of another class.
details of an object and providing a public interface for interacting
ep'!:thi code organized and ii. In Multilevel Inheritance, one cias[can inherit from a derived class.
with the object . This helps t -<, k-R Hence, the derived class becomes the base class for the new class.
maintainable. jf'
iii. As shown in Fig. 1.16.2, Class C is subclass of B and B is a of
iii. Inheritance: Inheritance is the ability of a class to inherit properties
subclass Class A.
and behaviors from another class. This allows for code reuse and
makes it easier to manage comP,lex codes.
iv. Polymorphism : Polymorphism is the ability of objec~to take on
multiple form~. InJava, ~ ymorphism is achieved throu!cl'J :{~thod
overloading and method'overriding. ·• · ,,#
~ ~ ~
v. Abstraction: Abstraction is the process,of creatj.ng,abstract classes
?r interfac:s that defi~e a set of propertiJ~ ~.~ bEiha~ or s without
=plementing them. This allows for greater flexibility and modularity
in t he code. kJ•· ·. ,/
6.
·" ,,.
In Java, these concepts are implem~ ted thr9,V,gh various language
Fig.1.16.2.
feat ures such as classes, objects, S:c9ess modifiers, constructors, 8. Hierarchical Inheritance :
inheritance, interfaces, andp.bstract .cl~ s. \ i single parent class has multiple
i. Hierarchical inheritance is w.hen
7. By using these features! d~vvl}lopers can create well-organized, child classes that inherit from it •.
, maintainable, ~d.extensi~le cov . ii. In Hierarchical Inheritance., one class is inherited by many sub
1
j
;91iJI 1.18. Explam m detail about vanous types of inheritance in
classes.
iii. In Fig. 1.16.3, Class B, C, and D inherit the same class A.
Java with neat sketch.
OR
~ith diagrammatfc illustration and Java programs illustrate the
different types ofmheritance.
ClassD
~ -~ J
In Java, there are five types of inheritance:
Class B
1-13 B (MCA-Sem-2)
Object Oriented Programming l-14B (MCA-Sem-2) Introduction
4. Multiple Inheritance: 'nh •t from more than 3. Simple and easy to learn : Java is designed to be simple and easy to
i. Multiple inheritance is when a child class J en s learn, with a syntax that is similar to other popular programming
one parent class. languages like C++ and C#.
t d more than one class. 4. Secore : Java has built-in security features that make it a secure
ii. In Multiple Inheritance one class ex en s
programming language. For example, Java programs run inside a
iii. In Fig. 1.16.4, Class C extends Class A and ClassB both.
sandbox environment, which prevents them from accessing resources
Class B on the host system without permission.
Class A
5. Robust: Java is designed to be robust and reliable, with features like
automatic memory management (garbage collection) and exception
handling that help to prevent crashes and errors.
Class C
6. Multi-threaded : Java supports multi-threading, which allows
Fig.1.16.4. developers to create programs that can execute multiple tasks
simultaneously. -•
5. Hybrid Inheritance : ,. 7. Rich API: Java has a rich API (Application Programming Interface)
i. Hybrid inheritance is a combination of two or more types of that includes a wide range of pre-built libraries and too!s that make it
inheritance. "' easy to develop complex applications.
ii. For example, it can be a combipation of single inheritance and 8. Scalable: Java is designed to be scalable, whiclifueans that it can be
multiple inheritances, or a compination.ofhierarchical inheritance used to develop applications of any s&.. fromimlllll applications to large-
and multilevel inheritance. ' .' , · scale enterprise applications.
iii. In Fig. 1.16.5, all the public and.protected members of.Class A are
inherited into Class D, first via Class Band secondly vrn Class C. Que 1.18.1 Write a short noie'on tJie.J ava Environment.
Auwer I
Following are the most important characteristics/features of Java:
5. The JRE is another important ~omp,onent of the Java Environment. It
includes the JVM, as well as the libraries and other resources needed to
run Java applications. 6. The JRE is required to run any J ava application
1. Object-oriented : Java is an object-oriented programming language, on a user's machine.
which means that it is designed to organize code around objects that
7. The Java compiler is used to compile Java code into bytecode that can be
encapsulate data and behavior. executed by the JVM.
2. Platform-independent: Java code can be run on any platform that 8. The compiler is included in the JDK and can be used to compile Java
has a Java Virtual Machine (JVM) installed, including Windows, Linux, code from the command line or from an integrated development
and MacOS. This is because Java code is compiled into bytecodr , which environment (IDE).
can be run on any platform that has a JVM.
name="";
age= O;
!
IQae 1.21, What i• method? Bow method i• defined? Give Example.
9.
The fourth constructo r takes all three argument s and sets all three
variables.
By defining multiple constructo rs with different paramete rs, we have
made the 'Employee ' class more flexible and easier to use .
e:xample explain how finaliae() method
Aa~· .I
c-
.9!e·~.11,I State the p ~ offinalia e() method in Java. With an
be uaed in Java program.
1.The finalize( ) method in Java is a method that gets called by the garbage
collector before an object is destroyed .
1- 23 B (MCA -Sem-2)
Objec t Orient ed Programming 1-24 B (MCA-Sem-2) Introduction
to perfor m some ver&atile and flexible
2. Its purpos e is to provide a way for the progra mmer 3- By using method overloading, we can create more
cleanu p operat ions before the object is garbage
collected.
ds that can handle differe nt types and numbe rs of parameters,
metho
file handles, closing g our code more efficie nt and easier to use.
3. This can be useful for releas ing resour ces like makin
Java :
databa se connections, or freeing up memo ry. 4. Following is an example of method overloading in
on finalize () to perform
4. However it is impor tant to note that relying solely public class Calcul ator (
no guaran tee that
cleanu p operat ions can be unreliable becaus e there's public int add(in t a, int b) (
it will be called in a timely manne r, or even at all.
try-wi th-reso urces or a return a+ b;
5. It's better to explicitly releas e resour ces using
finally block.
can be used in a Java public double add(double a, double b) {
Exam ple: Following example show how finalize()
progra m : return a+ b;
public class MyCiass [
privat e File file; public int add(in t a, int b, int c) (
public MyClass(Stri ng filenam e) ( return a+ b + c;
file = new File(filename );
~ public static void main(String0 args) (
}
protec ted void finalize() ( , Calcul ator calc = new Calculator(};
try( ~"- · int suml = calc.add(t 32;
if (file != mill) ( ,~
file.i:tose(); y .,,
'
double sum2 = qa.leadd(2.5\"3.5);
int sum3 = c!J}c.ad d(2,~3; 4);
'\, p System .out.println(i'Sum 1:" + suml);
} ~ ,/
] catc~ OEx~ P,tion e) [ System~ t.print ln("Su m 2:" + sum2>?
}
Que 1.27.
r. .;
j Expla in metho d overlo ading in Java ? Illust rate with
Que 1.28. j Expla in metho d overr iding in .Tava
example.
? Illusir aie with an
OR
an exam ple. Outlin e metho d overr iding wiih an example.
1-25 B (MCA-Sem-2)
Object Oriented Programming
l-26B (MCA-Sem-2) · lntroductioili
3. When an overridden method is called from within its subclass, it will
always refer to the version of that method defined by the subclass. ii. protected : The 'protected' access specifier allows access from the
Following is an example of method overriding in Java : same class, as well as any subclasses and classes in the same package.
4. Protected methods and variables can be accessed within the class
public class Animal ( as well as by any subclass or class in the same package. '
public void makeSound() { iii. default (no keyword) : The 'default' access specifier allows access
System.out.println("The animal makes a sound"); from within the same package only. Methods and variables with no
access specifier are considered to have default access.
iv. private: The 'private' access specifier is the most restrictive, and
allows access only from the same class. Private methods and
public class Dog extends Animal { variables cannot be accessed from any other class, even subclasses.
@Override 4, By using access specifiers, we can control the level of access that different
classes, methods, and variables have within our program, making it
public void makeSoundO {
more secure and easier to manage. -~
System.out.println("The dog barks");
5. It's important to choose the appropriate accessspecifier fij'each element
of our program to ensure that it's accessible to the right classes and
methods, and not accessible to others that' should net have access.
1- 27 B (MCA-Sem-2)
Object Oriented Programming 1- 28 B (MCA-Sem-2) Introduction
'static' methods : The comments can be used to provide information or explanation about
to the class itself, rath er t h an to any
b. bel
2.
i. These are methods that ong the variable, method, class or any statement.
particular instance of the class. 3. It can also be used to hide program code for specific time.
d . the 'static' keyword and can be called using
ii. They are declare usmg th d me For example · 4. There are 3 types of comments in Java :
the class name, followed by th e me O na · ·
i. Single-line comments : These comments start with two forward slashes
public class MyClass I (If)and continue to the end of the line. Single-line comments are used
static int x = O; for short comments or to explain specific lines of code. For example :
public static void increment() I II This is a single-line comment
x++; int x = 10; II This line initializes the variable x to the value 10
ii. Multi-line comments : These comments start with a forward slash
and an asterisk (/) and end with an asterisk and a forward slash (/).
'\?• Multi-line comments are used for longer comments that span multiple
iii. In this example, 'increment()' is a 'static' metbo d th~9ielo~gs to ~he lines. For example : ~
'MyClass' class. It increments the value ofthe 1static vanable 'x . r ~
viii. booiean: used to represent true/false values. 6. Null literal : The null literal is used to represent a reference that does
not refer to any object. It is typically used to indicate the absence of a
B. Referenc e Data Types : value.
1. Reference data types are used to store references to objects .
2. Que 1.34. , Explain in detail about variaWe in Java.
Unlike primitive data types, they are objects themselve s and can be
assigned null.
Answer
3. Some of the reference data types in Java are :
1. A variable is a container which holds the value and that can be changed
i. String: used to represent a sequence of characters . during the execution of the program.
ii. Array: used to store a collection of elements of the same data type. 2. A variable is assigned with a datatyoe.
iii. Class : used to represent a class definition. 3. All the variables must be declared before they can be used.
iv. Interface : used to represent an interface definition. 4. There are three types of variables in Java :
v. Enumera tion : used to represent a set of constants. A Local Variable :
Que 1.33. , What are literals? Explain the types of literals supporte 1. A variable defined within a block or method or constnx:ro r is called local
d variable .
by Java.
2. These variables are created when the bloclt in eutered,or the function is
Answer called and destroyed after exiting from the block or when the call returns
from the function.
A Literals :
3. The scope of these variables exists only within the bloc.k in whlch the
1. In Java, a literal is a constant value that is explicitly defined in the
variable is declared i.e ., we can accll6S these variable only within that
source code of a program. block.
2. Liter.als are used to represent values such as numbers, character s, and B. Instance Variable :
boolean values in a program.
1. Instance variables are non-static variables and are declared in a class
B. Types of literals supporte d by Java are :
outside any method, constructo r or block.
1. Integer literals: Integer literals are used to represent whole numbers. 2. AB instance variables are declared in a class, these variables are created
They can be specified in decimal, octal, or hexadecim al format . For when an object of the class is created and destroyed when the object is
example, 42, 052, and 0x2A are all integer literals. destroyed .
1-31 B (MCA-Sem-2)
Object Or iented Program ming 1-32 B (MCA-Sem-2) Introduc tion
variables.
3. Unlike local variables we may use access specifiers for instance 7. ~nstanc eof operato r : This operator is used to check if an object
is an
~y access specifier then the default access specifier as
Ifwe do not specify m~tance of a particul ar class or a subclass of that class. It's written
will be used. obJect mstance of class.
C. Static Variab le:
Que 1.36., Explain differen t control stateme nts in Java.
1. Static variable s are also known as Class variable s.
difference OR
2. These variable s are declared similar to instance variables; the in Java ?
variable s are declared using the static keyword within a What are the three categor ies of control stateme nts used
is that static OR
class outside any method construc tor or block.
Explain the selectio n stateme nt in Java.
variable
3. Unlike instance variable s, we can only have one copy of a static
Answe r
per class irrespec tive of how many objects we create.
program
4. Static variable s are created at start of program executio n and
destroyed Contrnl stateme nts in J ava are used to control the flow of
n. They allow the program to make decision s,. loop over a block
automat ically when executio n ends. execut10
of control
of code, and _break out of loops. Following are the main types
stateme nts m J ava :
Que 1.35. j Explain differen t operato rs in Java. used to
A Conditi on_a l/Select ion stateme nts : These st atement s are
ma ke dec1s10ns based on a condition.
Answe r
nt. It is
Java has severa l types of operator s, each of which perform
s a specific 1. if stateme ~t : It is the most simple decision making stateme
nts will
functi on on one or more operand s. Following are some of
the main used to decide whether a ce rtain st atement or block of stateme
executed or not i.e. , if a certain conditio n is true then a block of
categori es of oper ators in J ava : be
stateme nt 1s executed otherwis e not.
1. Arithm etic operato rs : These operator s are used
for mathem atical
ition.
calculat ions and include + (addition ), - (subtrac tion),* (multiplication), / 2. if-else stateme nt: The J ava if-else stateme nt also tests the.cond
block
(division ), % (modulus or remainder), ++ (increme nt), and -- (decrem
ent). It executes the 'if' block if condition is true else if it is false the 'else'
1s executed .
operato rs a re used for compari ng values
2. Relatio nal operato rs: These nt inside
to ), >= 3. Nested if-else stateme nt : It is using one if or else-if stateme
and include< (less than),> (greater than ), <= (less than or equal another if or else-if stateme nt(s).
(greater t han or equal to), == (equal to), and!= (not equal to).
from the
rati ons 4. if-else-i f ladder stateme nt: The 'if' state ments are executed
3. Logical operato rs : These oper ators ar e used for logical ope conditio ns controlli ng the if are true, the stateme nt
NOT). top d_own. T_h e
and include && (logica l AND), 11 (logical OR), a nd! (logical bypassed .
assoc iated with that ifis executed , and the r est of the ladder is
values to
4. Assignm ent operato rs: These operato rs are used to ass ign If none of the conditions is true, then the fin al else stateme
nt will be
ass ign), -=
variable s and include = (simple assignm ent), += (add and executed.
nd assign), 5.
(subtrac t and assign ), *= (multipl y and assign ), I= (divide a Switch statem ent: The switch stateme nt is J ava's multi-wa
y branch
a nd %= (modulu s and assign). st atement . It provides till easy way to dispa tch executio n to different
5. Bitwise operato rs : These oper a tors are used to perform
bitwise parts of your code based on the val ue of an expression .
operatio ns on integers and include & (bitwise AND), I (bitwise
OR), " B. execute
(left shift),» (signed Iteratio n stateme nt (Loops) : Iteration statements are used to
complem ent or NOT),« ts
(bitwise XOR), - (bitwise a bloc k of code repeatedly. There are three types of iteration statemen
right shift), and >» (unsigne d right shift). in J ava :
ons I.
6. Conditi onal operato r: This operator is used for conditional expressi for : The fo r loo p is used when the number of it erations is known
in
s the
and is written as conditio n? expressi onl : expression2. lt evaluate advance.
otherwi se
conditio n and if it's true, it returns the value of express ion 1,
it returns the value of expression2.
Ans wer
A Arra y in Java :
s
that holds a fixed numb er of value
1. In Java , an array is a data struc ture ;>
of the same data type. . ·
array
mean ing the first elem ent ofan
2. Arra ys in Java are zero- index ed;
has an index of 0.
alloc ated.
3. In Java all a1Tays are dyna mica lly
B. Typ es of arra y :
1. One -Dimensi onal Arra ys :
er of value s of the same data t ype
i. It's an array that holds a fixed numb
onen ts: the type and the name .
ii. An array decla ratio n has two comp
ent type of the array .
iii. Type decla res the elem
deter mine s the data type of each elem
iv. The elem ent type ent t ha
comp rises the array .
'l
l
(_}bject Ori~nte d Program ming SQ-2 B (MCA-Sem-2)
SQ-1 B (MCA-Sem-2) 2 Marks Questions
user. In other words, it is the process of creating abstract data types
1
that provide a high-level interface to the user, while hiding
the
impleme ntation details.
UNI T
Intr odu ctio n .,_ A class must be declared as abstract in Java ifwe want to
define a
common interface or behavior for a set of related classes, but
we
(2 Marks Que stion s) don't want to provide a concrete implementation for all of
the
methods or attribute s.
,al:
~ '.i'"'
....
1.9. What do you mean~ inherita nce in OOP?
' -
Inherita nce allows us to-create new cl~ fro existing classes
inheritin g their data.and behavior - lnhentan cem~.des a wa! ~
' d ..:...,..e classes that are related \0 each other m
_,__"an
''1 " <)' reuse couo,-
. q -•
chi al ................
a
- --,."~ d through
S.No. .. In OOP inheritaI!,1:11,-lS ~ve
Aspect Class '" Object " hierar c ---~~ - ' '-
the use of parent and child classes.
1. Definitio n A blueprin t for creating, An instance of a class. y
objects.
1.10. Defin& po]ymo rphi~-. . . take ~n multiple forms or
2. 'd
Keyw.or 'class' keyword . l' ':}
Instanti ated using the
~ Polymor phism is t~e abili~ of oh\e~ : which they are used.
1n
~
beh~viors depending on . e conl orphism is ~cally achieved
'new' keyword .
object-or iented progr&;[llDllllC, po ym .ding
3. Memory Does not occupy me~ory Occupie s memory when thr~ugh inheritan ce an,dmethod ovem .
allocation until an object is cre,ted . instantia ted. , -~ i....igae e in Java?
... 111 What are various types u,µuaa-• •
1.4. What is abstrac tion in Java? • · ti types of inheri'8n ce :
Jl8 In Java, ther_e are ve
aa: Abstract ion refers to the practice of hiding impleme ntation
details 1. Single Inbentan ~e
while showing only the necessa ry informa tion to the user. In 2. Multilevel lnhen ~
OOP,
abstract ion is achieved through the use of interfac es and abstract 3. Hierarchical ~entan ce
classes. 4. Multiple lnh~ntan ee
1.15. Define data abstraction. 5_ Hybrid Inbentan ce
ri ucslfeaturell of Java.
Mil Da~ lU>f:ltr!lCtion is a program ming concept that refers to the process 1.12. Give the ch&raCWh s cteristicslfeatures of Java:
of simplifying complex data structur es by hiding unneces sary Ulli Follo~ are the c ara
details
and exposing only the essentia l features that are relevant l . Object-onented
to the
....
1.14. What is Java Environment? '
,, F
'
-
loading in Java? nJ.ti 1
1.15. What is bytecode ? 1h 1.22. What is c o ~ over
, r ~= ·
the practice of defining- ~ P e
Constructor over10&9"mg 15 .th diff•t sign&ture. This allows
Bytecode is a binary representation_of Java code_that c ·. be.executed constructors for a: class, _e ~ ~ ~th diffeftllli 11ets-ofparameters,
on any pl~tform that:has a Java Virtual Mac~ne (~ ) Bytec~de
41 objects of the class to be rm . ' •
is a low-level code.that is not specific to anylfardwa.reor'operatmg making it more flexible and versatile. Y
system. When you run a Java program, the ~,l'~~ps the bytecode
and interprets it into machine code that can b!f,executed by the
1.23, What is method '. e l:Iiat.J)erforms a specific tas~.
underlying hardware. ·
Ans. In Java, a jnethod is a bl~o~ into reusable and.modular umt,
Aft 0
Methods are used to ~ ~write', and maintain.
1.16. What is Java Virt~al Machine (JVM},? which makes code easJer t<r
mac JVM is an abstract machine that provides a runtime environment · . medlodinJava.
for executing Java bytecode. When a Java program is compiled, the
1.24, State the purpose o f ~ ."' thod that gets called b~ the
source code is translated into bytecode, which is a set of instructions e finalize() method in J au 1:5 a ~destroyed. Its purpose is to
that can be executed by tlie .JVM. The JVM is responsible for US Th bage collector before an ob1ect t perform some cleanup
interpreting the bytecode and executing it on the underlying gar £ th programmer o
provide a way or ~ - tis garbage collected.
hardware. operations before the o ~ec
1.31. Can a Java source file be saved using a name other than
the clus name ? Justify.
. _ Yes, a Java source file can be saved using a name other than the
class name. In Java, the source file name and the class name can be
different. This is because Java follows a convention that requires
the file name to match the name of the public class declared in the
file only ifit exists.