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


Name some default packages in JDK and explain what


Download 1.52 Mb.
Pdf ko'rish
bet45/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   41   42   43   44   45   46   47   48   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

Name some default packages in JDK and explain what
they do in brief.
Answer:
The following are some default packages in Java:
java.util.Collection: This package includes all the
Collection API classes. So, classes/interfaces like List,


b.
c.
d.
115.
ArrayList, Set, HashSet, Map, HashMap are all part of this
package. In addition, it also has other classes like Date and
Calendar for Date handling.
java.io: This package has classes that help to perform
input/output operations like InputStream, FileInputStream,
FileOutputStream, BufferedReader, BufferedWriter, etc.
java.awt: This package has all classes for creating user
interfaces like Component, Container, Frame, etc.
java.util.concurrent: This package has all classes that
are useful for concurrent programming like Future, Executor,
ExecutorService, etc.
Is the following code valid? Explain the reasons.
package demo1;
public class Base {
protected int a;
}
package demo2;
public class Sub extends Base {
public void doSomething() {
System.out.println(“Value of a is “+a);
}
}
Answer:
The above code is valid and does not cause any compilation or
run time error. This code creates a super class called Base and a
sub–class called Sub. Both classes are in different packages.
The Base class has a protected field a which is accessed in the
sub–class doSomething() method. This is perfectly valid. Only


116.
117.


private fields from the base class are not accessible in the
sub–class. Fields with the protected access specifier are
accessible in the sub–class even if the sub–class is in a different
package.

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   41   42   43   44   45   46   47   48   ...   171




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