0% found this document useful (0 votes)
23 views

Theory_Questions_Answers_1-25

Theory xicse

Uploaded by

studing489
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Theory_Questions_Answers_1-25

Theory xicse

Uploaded by

studing489
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Answers to Questions 1-25

1. Which element is num[9] of array num?

The element at num[9] is the 10th element of the array because array indexing starts at 0.

2. What is the difference between operator and expression?

An operator is a symbol (e.g., +, -, *) used to perform operations, while an expression combines

operators and operands (e.g., 5 + 3).

3. What do you mean by compound statement? Give example.

A compound statement is a block of code enclosed in braces {}. Example:

int x = 5;

int y = 10;

4. State one similarity between while and do-while loop.

Both loops are used for iteration, but do-while ensures the loop executes at least once.

5. Explain break and continue statements?

'break' exits a loop or switch prematurely, while 'continue' skips the current iteration and moves to

the next one.

6. How are primitive and reference types passed from the function?

Primitive types are passed by value, while reference types are passed by reference.

7. What is a wrapper class? Define with the help of an example.

Wrapper classes in Java provide object representation for primitive types. Example: Integer wraps

int.
8. What is the purpose of new operator?

The 'new' operator dynamically allocates memory for objects or arrays.

9. Define impure function.

An impure function produces side effects or depends on external states.

10. What do you understand by private visibility of a method?

Private methods can only be accessed within the class where they are defined.

11. Define a default constructor.

A default constructor is a constructor without parameters that initializes objects with default values.

12. What is a package? Give an example.

A package in Java is a namespace for organizing classes and interfaces. Example: java.util.

13. Define two types of Java programs.

1. Application programs: Standalone programs run with a main method.

2. Applet programs: Run inside a web browser.

14. Why do we need a constructor as a class member?

Constructors initialize an object's state when it is created.

15. Explain if-else construct with an example.

The if-else construct executes one block of code if a condition is true, else another block. Example:

if (x > 0) { System.out.println("Positive"); } else { System.out.println("Negative"); }

16. Name a package that gets invoked by default.

The java.lang package is invoked by default in Java programs.

17. State difference between = and ==?

'=' 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?

Only one return statement is executed, the first one encountered.

19. Name the keyword to use the classes defined in a package.

The 'import' keyword is used to include classes from a package.

20. Mention any two attributes for class declaration.

1. Access modifiers (e.g., public, private).

2. Class name (e.g., MyClass).

21. What is inheritance? How is it useful in Java?

Inheritance allows a class to acquire properties of another class, promoting reusability and

polymorphism.

22. Differentiate between base and derived class.

Base class (superclass) provides properties to other classes, while derived class (subclass) inherits

from the base class.

23. What is the use of exception handling in Java?

Exception handling manages runtime errors, ensuring the program does not crash abruptly.

24. What is array.length? What is array[4]?

'array.length' gives the size of the array, while 'array[4]' accesses the 5th element.

25. Explain instance variable with the help of an example.

An instance variable is unique to an object. Example: 'int age;' inside a class.

You might also like