BIM 2nd OOP with Java New course model question SOLVED(2023)

0




"Group - A"

Brief Answer Questions:

1. What is bytecode?

=> Bytecode in Java is a platform-independent binary format that is generated by the Java compiler. It is executed by the Java Virtual Machine (JVM) and serves as an intermediate representation of Java code. Java source code is compiled into bytecode, which can then be executed on any platform that has a compatible JVM.


2. Differentiate between break and continue.

=> In Java, "break" and "continue" are both control statements used in loops. The main difference between them is as follows:

    "break" statement is used to terminate the loop and exit its execution when a certain condition is met. When the "break" statement is executed in a loop, the control of the program moves to the statement immediately following the loop.

    "continue" statement is used to skip the current iteration of the loop and move to the next iteration when a certain condition is met. When the "continue" statement is executed in a loop, the control of the program moves to the next iteration of the loop.


3. What do you mean by associativity of an operator?

=> Associativity is a property of operators in programming languages that determines the order in which operations are performed when there are multiple operators of the same precedence in a single expression.


4. How 2D array is declared in Java?

=> dataType[][] arrayName = new dataType[rows][columns]

int[][] myArray = new int[3][4] 

int[][] myArray = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}


5. Why constructor is needed?

=> Constructors are a special type of method in Java that is used to create objects and initialize their instance variables. Constructors have the same name as the class and do not have a return type.


6. What is garbage collection in Java?

=> Garbage collection (destructor) is a mechanism in Java that automatically manages the memory used by objects in a program. When objects are created in Java, they are stored in the heap, which is a part of the memory that is allocated to the Java Virtual Machine (JVM).


7. What do you mean by dynamic method dispatch?

=> Dynamic method dispatch is a mechanism in Java that allows a subclass to override a method of its superclass and provide its own implementation. This mechanism enables the Java Virtual Machine (JVM) to determine at runtime which version of a method to execute, based on the actual object that is referred to by a superclass reference variable.

In dynamic method dispatch, a reference variable of the superclass type is used to refer to an object of the subclass. When a method is called using this reference variable, the JVM determines which version of the method to execute based on the actual type of the object. This means that the method that is executed can be different from the method declared in the superclass.


8. What is the difference between the final and finally keyword?

=> "final" is a keyword used to declare a variable, method, or class as constant or unchangeable. When applied to a variable, it means that the variable cannot be reassigned to a new value once it has been initialized. When applied to a method, it means that the method cannot be overridden by a subclass. When applied to a class, it means that the class cannot be subclassed.


"finally" is a keyword that is used in a try-catch-finally block to ensure that a block of code is always executed, regardless of whether an exception is thrown or caught. The code inside the "finally" block will be executed even if an exception occurs and is caught by a "catch" block, or if the try block completes without an exception being thrown


9. What is the wildcard in Java?

=> In Java, a wildcard is a special character ("T") that is used to represent an unknown type. Wildcards are used in generics to define a type parameter that can accept any type or a bounded set of types. There are two types of wildcards in Java:

Unbounded Wildcard: This is denoted by the "?" character and represents an unknown type. It is used in situations where a method or class can accept any type.

Bounded Wildcard: This is denoted by "? extends Type" or "? super Type" and represents a bounded set of types. It is used when a method or class can accept any type that is a subtype or supertype of a given type.


10. Define autoboxing with an example?

=> Autoboxing is a feature in Java that automatically converts a primitive data type into its corresponding wrapper class object. This conversion is performed by the Java compiler at compile-time and is a convenient way to use primitive data types as objects.

example:

int num = 10;        // primitive data type

Integer obj = num;   // autoboxing to wrapper class object


                "Group - B"


Post a Comment

0Comments
Post a Comment (0)