© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On Package▼

Java Interview Questions On Package

1. What is a Package?

Answer

  • l A package is a collection of related classes
  • l To create a package use package keyword
  • l The package statement should be the first line in your .java file only comments are allowed
  • before package statements
  • l The package statement should be placed before the import statements
  • l To import a package in to your class use import keyword

2. How we declare the classes in java source file?

Answer
In Java the source file must be saved as with .java extension, and it must have only one public class and it can have multiple non-public classes. When you compile a Java source file the byte code generated with .class extension.            

For example in a java file if you have one public class and 3 three non-public classes, then one .class for public class and three .class files for non-public classes will be generated by the compiler.

3. How we declare inner class?

Answer:
The concept of inner classes was introduced in Java Development Kit 1.1. The concept is very simple like any regular class but the inner classes are declared inside any other class.

The enclosing class becomes the part of the fully qualified name of the inner class. We can create the static inner class also.l You don't need a outer class object to create an instance of a static inner class.

4. What is the 'anonymous' Inner Classes?

Answer:
In certain situations an inner class can also be defined without name. This type of inner class
declarations are called anonymous inner classes. This type of inner class declaration generally you will see in GUI event handling mechanism of Java.

Key Points about Inner Classes:

  • l An anonymous inner classes cannot have constructor.
  • l The declaration and instantiation of anonymous inner classes should be done at the same place.
  • l An anonymous class can either explicitly extend a class or explicitly implement an interface, but
  • you cannot do both extending and implementing an interface.

5. What restrictions are placed on the location of a package statement within a source code file?

Answer:
A package statement must appear as the first line in a source code file (excluding blank lines and comments)

6. Which package is always imported by default?

Answer:
The java.lang package is always imported by default.

SLogix Student Projects
bottom