Answers Already Graded A
How do you create an object in Java?
✔✔ Using the `new` keyword with a constructor.
What is the main advantage of using an interface in Java?
✔✔ It allows multiple classes to follow a common contract and supports multiple inheritance.
What is the purpose of the `this` keyword in Java?
✔✔ It refers to the current instance of the class.
How do you convert a `double` to an `int` in Java?
✔✔ Using explicit casting: `(int) value`.
What is method overloading in Java?
✔✔ Defining multiple methods with the same name but different parameters.
1
,How do you read user input in Java?
✔✔ Using `Scanner` class and `next()` or `nextLine()` methods.
What is the difference between `ArrayList` and `LinkedList`?
✔✔ `ArrayList` is better for fast random access, while `LinkedList` is better for frequent
insertions and deletions.
How do you generate a random number in Java?
✔✔ Using `Math.random()` or `Random` class.
What does the `finally` block do in a `try-catch-finally` statement?
✔✔ It executes code after `try` and `catch`, regardless of exceptions.
How do you create a thread in Java?
✔✔ By extending `Thread` or implementing `Runnable`.
What is the difference between `abstract` class and `interface`?
2
, ✔✔ An abstract class can have both implemented and abstract methods, while an interface only
has abstract methods by default.
What is the main purpose of the `static` keyword in Java?
✔✔ It allows a method or variable to belong to a class rather than an instance.
How do you create an infinite loop in Java?
✔✔ Using `while(true){}` or `for(;;){}`.
What is the difference between `==` and `.equals()` in Java?
✔✔ `==` compares memory addresses, while `.equals()` checks logical equality.
How do you declare a constant variable in Java?
✔✔ Using the `final` keyword.
What is the default value of an uninitialized `int` variable in Java?
✔✔ 0
3