Theory_Questions_Answers_1-25
Theory_Questions_Answers_1-25
The element at num[9] is the 10th element of the array because array indexing starts at 0.
int x = 5;
int y = 10;
Both loops are used for iteration, but do-while ensures the loop executes at least once.
'break' exits a loop or switch prematurely, while 'continue' skips the current iteration and moves to
6. How are primitive and reference types passed from the function?
Primitive types are passed by value, while reference types are passed by reference.
Wrapper classes in Java provide object representation for primitive types. Example: Integer wraps
int.
8. What is the purpose of new operator?
Private methods can only be accessed within the class where they are defined.
A default constructor is a constructor without parameters that initializes objects with default values.
A package in Java is a namespace for organizing classes and interfaces. Example: java.util.
The if-else construct executes one block of code if a condition is true, else another block. Example:
'=' assigns a value to a variable, while '==' checks for equality between two values.
18. If a function contains several return statements then how many of them will be executed?
Inheritance allows a class to acquire properties of another class, promoting reusability and
polymorphism.
Base class (superclass) provides properties to other classes, while derived class (subclass) inherits
Exception handling manages runtime errors, ensuring the program does not crash abruptly.
'array.length' gives the size of the array, while 'array[4]' accesses the 5th element.