How to Create a Package in Core Java

In this tutorial how to create a Package in Core Java  is shown.

Code:

TestPackage.java

package demo;

class A
{
private int a,b;
private String str;

A()
{
a=b=1;
str=new String();
}

A(int a,int b,String str)
{
this.a=a;
this.b=b;
this.str=str;
}

void display()
{
System.out.println(“A: “+a);
System.out.println(“B: “+b);
System.out.println(“str: “+str);
}
}

class B extends A
{
private int c;

B()
{
super();
c=1;
}

B(int c,int a, int b,String str)
{
super(a,b,str);
this.c=c;
}

void display()
{
super.display();
System.out.println(“C: “+c);
}
}

class TestPackage
{
public static void main(String[] args)
{
B b2=new B();
b2.display();
B b1=new B(6,7,8,”Hello”);
b1.display();
}
}

Add a Comment

Your email address will not be published. Required fields are marked *