Difference between Inheritance and package
Advertisements
Difference between Inheritance and package in Java
Both package and Inheritance in Java are used for re-use features. Some differences between them are given below;
- Inheritance concept always used to reuse the feature within the program between class to class, interface to interface and interface to class but not accessing the feature across the program..
- Package concept is to reuse the feature both within the program and across the programs between class to class, interface to interface and interface to class.
Example Package in Java
Example
package mypack; public class A { public void show() { System.out.println("Show Method"); } }
Example Inheritance in Java
Example
class Faculty { float salary=30000; } class Science extends Faculty { float bonous=2000; public static void main(String args[]) { Science obj=new Science(); System.out.println("Salary is:"+obj.salary); System.out.println("Bonous is:"+obj.bonous); } }
Google Advertisment