Name four Container classes.

Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane. In Core Java, container classes typically refer to classes that hold and manage other objects. Here are four container classes in Java: ArrayList: It’s a dynamic array implementation of the List interface, allowing the dynamic resizing of the array as elements are added or removed. java List<String> list = new ArrayList<>(); LinkedList: It’s … Read more

What is the return type of a program’s main() method?

A program’s main() method has a void return type. In Core Java, the return type of a program’s main() method is void. The main() method is the entry point of a Java program, and it is declared with the following signature: java public static void main(String[] args) { // Program logic goes here } The … Read more

What is casting?

There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or arraytype reference. In Java, casting refers to … Read more

What happens when you invoke a thread’s interrupt method while it is sleeping or waiting?

When a task’s interrupt() method is executed, the task enters the ready state. The next time the task enters the running state, an InterruptedException is thrown. When you invoke a thread’s interrupt method while it is sleeping or waiting, it will cause the thread to receive an InterruptedException. This interruption can be used to gracefully stop the thread or … Read more

What restrictions are placed on method overloading?

Two methods may not have the same name and argument list but different return types. In Core Java, there are certain restrictions placed on method overloading. These restrictions help maintain clarity and consistency in the language. The key restrictions on method overloading in Java are: Parameter Types and Number: Overloaded methods must have a different … Read more