Spring Question
Spring Question
Inner classes are nested inside other class. They have access to outer
class fields and methods even if the fields of outer class are defined as
private. public class Person { class clsName { // inner class defines the
required structure String first; String last; } // array of name objects
clsName personArray[] = {new clsName(), new clsName(), new
clsName()}; } Normally inner classes are used for data structures like one
shown above or some kind of helper classes. (B)What are packages?
Packages group related classes and interfaces together and thus avoiding
any name conflicts. From OOP’s point of view packages are useful for
grouping related classes together. Classes are group together in a
package using “package” keyword. Below is a sample snippet for a
package which groups “Class1” and “Class2” in one package
“Package1”.88 package Package1; public class Class1 { public void
displayClassName() { System.out.println(" I am class1 from Package1"); }
}public class Class2 { public void displayClassName()
{ System.out.println(" I am class2 from Package1"); } } When we want to
use the above “package1” in project we need to use the import keyword.
import Package1.*; public class clsRun { public static void main(String[]
args) { Package1.Class1 objp1Class1 = new Package1.Class1();
objp1Class1.displayClassName(); }} Note: - You can add a package using
eclipse using the wizard as shown below.89 Figure 1.27 : - Adding package using eclipse
wizard In order to make concepts more clear there is a sample package
project shipped in CD in “package” folder. Below is the solution of the
package project. There two packages “Package1” which has “Class1”
class and “Package2” which has again a class by name “Class1”. Figure 1.28 :
- Solution for package project90 Figure 1.29 : - “clsRun” class for package project In “