0% found this document useful (0 votes)
12 views2 pages

Java OOPs: Key Viva Questions

Useful for 3 Rd sem vtu students

Uploaded by

naikmeghana369
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)
12 views2 pages

Java OOPs: Key Viva Questions

Useful for 3 Rd sem vtu students

Uploaded by

naikmeghana369
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

OOPS with Java: Viva Questions

[Link] is meant by keyword in java? give two examples.

2. Differentiate between an instance variable and local variable?

3. Differentiate between an operator and an expression.

4. What is a class?

5. What is method and state its advantage?

6. What is a Constructor. List its types?

7. What is the access modifiers allowed for constructor?

8. What is a loop? List various loops?

9. What are the various decision-making statements used in java?

10. What is the use of static keywords?

11. Differentiate between entry-controlled loop and exit controlled loop?

12. What is super keyword?

13. What is inheritance?

14. What is polymorphism? List its types?

15. What is method overloading?

16. Which are the access modifiers allowed for constructor?

17. Differentiate between method overloading & overriding.

18. What is a package?

19. List the types of packages in Java.

20. What are the types of access modifiers provided by java?

21. What is abstraction?

22. What is the advantage of Abstract class in Java?

23. What is an interface in Java?


24. What is a thread? List different types of thread?

25. State any 3 thread methods with their use?

26. List stages in life cycle of thread in java.

27. What is an exception? How to handle it?

28. What is the use of finally block?

29. What are the Exception Handling Keywords in Java?

30. What happens when an exception is thrown by the main method?

Common questions

Powered by AI

Method overloading and method overriding are both mechanisms to achieve polymorphism in Java. Method overloading occurs when two or more methods in the same class have the same name but different parameters, allowing a method to perform different tasks based on input. It occurs at compile time. Method overriding, however, involves defining a method in a child class with the same name and parameters as in its parent class, allowing the child class to provide a specific implementation. This occurs at runtime. Overloading supports static polymorphism, whereas overriding supports dynamic polymorphism, providing flexibility and diverse behavior .

Java's decision-making statements govern the flow of execution based on conditions, central to control structure in programming. The primary types of decision-making statements include 'if', 'if-else', 'switch', and nested 'if'. 'If' supports conditional execution, 'if-else' allows branching logic, 'switch' enables multiple paths via case handling. These constructs form the backbone of logical flow, facilitating conditions, branching, and unique path selection within algorithms .

Instance variables are declared within a class but outside any method, constructor, or block, and are accessible from any method within the class. They are associated with the object itself and are created when the object is instantiated, lasting for the lifetime of the object. Local variables, in contrast, are declared within a method and are accessible only within that method. Their lifecycle is limited to the duration of the method execution. This distinction affects scope, as instance variables can be accessed by any method of the class, whereas local variables are confined to the method where they're declared .

Inheritance in Java allows one class to inherit fields and methods from another, promoting code reusability and organizational structure. By creating a hierarchy of classes, inheritance reduces redundancy as shared methods and attributes need defining only once. It simplifies maintenance, as changes to the base class propagate across subclasses. Inheritance enhances polymorphism, allowing classes to be treated generically while enabling specific implementations. However, it can also lead to complex dependencies if not managed properly .

The 'finally' block in Java's exception handling is utilized to execute code after a 'try' block, regardless of whether an exception is thrown. It is crucial for resource deallocation, such as closing files or releasing network connections, ensuring these actions occur even if an exception occurs. Compared to other blocks, while 'try' addresses code execution and 'catch' handles exceptions, 'finally' assures necessary cleanup, contributing to robustness and stability in resource management within code .

The 'super' keyword in Java is used within a subclass to refer to its immediate parent class object. It plays a critical role in inheritance by allowing access to parent class methods and constructors, thus enabling method overriding. When a method in a subclass overrides a parent class method, the 'super' keyword can be used to call the overridden method, allowing for extended functionality rather than replacement. This facilitates polymorphic behavior where subclass methods can work upon parent class methods .

Entry-controlled loops and exit-controlled loops differ in the execution sequence. Entry-controlled loops, like 'for' and 'while', evaluate the loop condition before executing the loop code block, which can result in zero executions if the condition is false from the start. Exit-controlled loops, such as 'do-while', execute the code block at least once, as they test the condition after. This distinction affects scenarios where the code block must execute a minimum of once, making exit-controlled loops suitable in such instances .

Encapsulation in Java is the bundling of data (variables) and methods that operate on the data into a single unit or class. It restricts direct access to some components and can prevent unauthorized interaction, enhancing security. By allowing controlled access through public methods, encapsulation supports modularity, making it easier to manage and update code. Changes to encapsulated data require minimal impact on external code, promoting independent module development and maintenance .

The 'static' keyword in Java is used to define methods or variables that belong to the class, rather than instances of the class. This allows them to be accessed without creating an instance of the class. Static variables can be shared across all instances, maintaining a single copy of the variable. Static methods can be called without object references, facilitating utility or factory methods. This alters standard variable and method behavior, contributing to memory efficiency and ease of use in utility functions .

An Abstract class is preferable over an Interface when you need to share code among several closely related classes. While interfaces declare methods without a body, abstract classes allow you to write certain implementations; thus, if different implementations share common behavior, it can be implemented in an abstract class. Additionally, abstract classes are appropriate when you have to declare non-static or non-final fields and work with base functionality. Interfaces, however, are more suited for defining capabilities that multiple classes can implement irrespective of their place in the class hierarchy .

You might also like