Core Java - Interview Questions and Answers

201. Which are keywords in Java?

a) NULL
b) sizeof
c) friend
d) extends
e) synchronized
Ans : d and e

202. When must the main class and the file name coincide?

Ans :When class is declared public.

203. What are different modifiers?

Ans : public, private, protected, default, static, trancient, volatile, final, abstract.

204. What is an example of polymorphism?

Inner class
Anonymous classes
Method overloading
Method overriding
Ans : c


Packages and interface

205. What are packages ? what is use of packages ?

Ans :The package statement defines a name space in which classes are stored.If you omit the package, the classes are put into the default package.
Signature... package pkg;
Use: * It specifies to which package the classes defined in a file belongs to. * Package is both naming and a visibility control mechanism.

206. What is difference between importing "java.applet.Applet" and "java.applet.*;" ?

Ans :"java.applet.Applet" will import only the class Applet from the package java.applet
Where as "java.applet.*" will import all the classes from java.applet package.

207. What do you understand by package access specifier?

Ans : public: Anything declared as public can be accessed from anywhere

private: Anything declared in the private can’t be seen outside of its class.
default: It is visible to subclasses as well as to other classes in the same package.

208. What is interface? What is use of interface?

Ans : It is similar to class which may contain method’s signature only but not bodies.
Methods declared in interface are abstract methods. We can implement many interfaces on a class which support the multiple inheritance.

209. Is it is necessary to implement all methods in an interface?

Ans : Yes. All the methods have to be implemented.

210. Which is the default access modifier for an interface method?

Ans : public.

Post a Comment

Mới hơn Cũ hơn