Difference between Inheritance and package

Advertisements

Prev Tutorial Next Tutorial

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);  
}  
} 

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet


For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements