Core java interview Questions You'll Most Likely Be Asked (Second Edition)


Scenario 3– Objects created within a method


Download 1.52 Mb.
Pdf ko'rish
bet73/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   69   70   71   72   73   74   75   76   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

Scenario 3– Objects created within a method
public void doSomething(){
String str1 = “Hello”;
}
public void callMethod(){
doSomething();
//str1 from doSomething becomes eligible for GC


}



SECTION
02
CORE JAVA
JAVA 8
JAVA 9
HUMAN RESOURCE



197.
198.
CHAPTER
01
Functional Interfaces
What is a functional interface? How can you create a
functional interface?
Answer:
A functional interface is an interface that has only one abstract
method. In order to create a functional interface, you simply need
to create an interface that has just one abstract method as shown
below:
@FunctionalInterface
public interface Multiplier {
public int multiply(int a, int b);
}
This code defines an interface called Multiplier. It has only a
multiply method. It has the @FunctionalInterface
annotation specified. This annotation is optional, it marks the
interface as a functional interface. So, if you try to add another
abstract method to the interface, the code causes a compilation
error.
Explain the java.util.Function package.
Answer:
The java.util.function is a new package added by Java 8. It has a
lot of built–in functional interfaces. Some of the interfaces in this
package are as follows:


a.
b.
c.
d.

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   69   70   71   72   73   74   75   76   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling