The general form to create a sub-package is
package package1.package2;
Where package2 is inside package1.
To use the classes and interfaces of package2 we can write the import statement as
import package1.package2;
Let us see a program that we are creating a package technology inside the package silan by writing the statement
package silan.software;
And in this sub-package we are declaring a class simple with a method display ( ).
package silan; package silan.software; public class simple { public void display ( ) { System.out.println("welcome 2 JavaRace"); } } import silan. software.simple; class Demo { public static void main (string args []) { Simple s =new Simple ( ); s.display (); } }
package Silan; class Technology { public void show( ) { } public void get( ) { } public static void main(String args[ ]) { System.out.println("package is created"); } }
import technology.Vivtech ; class SilanSoftware { public static void main( String args[ ] ) { technology.Vivtech v=new technology.Vivtech( ); System.out.println("art of java programming"); } }
package technology ; import technology.Vivtech ; class Silan { public static void main(String args[ ]) { Vivtech v=new Vivtech( ) ; v.show( ) ; } }
import technology ; class Silan { public static void main(String args[ ]) { technology.Vivtech v=new technology.Vivtech( ); System.out.println("programming in java"); } }
package main; class Base { public void Print() { System.out.println("Base"); } } class Derived extends Base { public void Print() { System.out.println("Derived"); } } class Main { public static void DoPrint( Base o ) { o.Print(); } public static void main(String[] args) { Base x = new Base(); Base y = new Derived(); Derived z = new Derived(); DoPrint(x); DoPrint(y); DoPrint(z); } }
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc