Reference Page: JAVA|SCALA|SWIFT|RUST|GO-Language|R-Language

Java Links : Learn     Interview Questions     Software IDE Java Jobs : Indeed.com     ZipRecruiter.com     Monster.com

Java Interview Questions - Page 2

< Previous Page              Next Page >
Question:What is the difference between 'throw' and 'throws' in Java?
Answer: In Java 'throw' is used to explicitly throw an exception, while 'throws' is used in method signature to declare the exceptions that a method might throw.

Both throw and throws are concepts of exception handling in Java. Throw can only propagate unchecked exceptions, while throws can declare both unchecked and checked exceptions.

Question: What is the difference between finalize() and finally in Java?
Answer: You can find the difference below:
• finalize() is a method in the Object class that gets called by the garbage collector before an object is garbage collected.
• finally is a block used in exception handling to ensure that a block of code is always executed, whether an exception is thrown or not.

Question: What is the 'static' keyword in Java?
Answer: The 'static' keyword in Java is used to create class-level variables and methods that belong to the class rather than to any instance of the class. 'static' members can be accessed directly using the class name without creating an instance of the class.

Question: Can you explain the concept of method overloading and method overriding in Java?
Answer: Please find the concept below:

Method overloading is the ability to define multiple methods in the same class with the same name but with different parameters.
Method overriding is the ability to define a method in a subclass with the same signature as a method in the superclass, thus replacing the superclass method in the subclass.

Overriding occurs when the method signature is the same in the superclass and the child class. Overloading occurs when two or more methods in the same class have the same name but different parameters.

Question: What is the difference between public, private, protected, and default access modifiers in Java?
Answer: You may find the difference below:

public members are accessible from any other class.
private members are accessible only within the same class.
protected members are accessible within the same package and subclasses.
Default access (no modifier) allows access only within the same package.

Question: What is the 'this' keyword in Java?
Answer: In Java 'this' keyword refers to the current instance of the class. It can be used to access instance variables and methods within the class and to differentiate between instance variables and parameters with the same name.

Question: Can you explain the 'super' keyword in Java?
Answer: The 'super' keyword in Java is used to refer to the superclass of the current object. It can be used to access superclass methods and constructors, and to call superclass constructors from subclass constructors.

< Previous Page Next Page >