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.
Do'stlaringiz bilan baham: