We have to create 3 different packages for this program and execute it.
Vehicle.java
package package1;
public abstract class Vehicle
{
public int year;
public abstract void getData();
public abstract void putData();
}
class FourWheeler extends Vehicle{
public void getData()
{
year=92;
}
public void putData()
{
System.out.println("Year of manufacture of the fourwheeler is"+year);
}
}
public abstract class Vehicle
{
public int year;
public abstract void getData();
public abstract void putData();
}
class FourWheeler extends Vehicle{
public void getData()
{
year=92;
}
public void putData()
{
System.out.println("Year of manufacture of the fourwheeler is"+year);
}
}
prog2.java
package package2;
import package1.*;
class TwoWheeler extends Vehicle{
private String EngineType="2-s";
protected String Brand="Y";
public String Color="Black";
public void getData()
{
EngineType="2-stroke";
Brand="Yamaha";
Color="Black";
year=88;
}
public void putData()
{
System.out.println("Year of manufacture of the twowheeler is"+year);
System.out.println("Engine type is " +EngineType+" ,Brand is "+Brand+" ,Color is "+Color);
}
void printprivate()
{
System.out.println("Accessing private variable"+ EngineType);
}
}
class MyTwoWheeler extends TwoWheeler
{
public String OwnerName;
MyTwoWheeler()
{
super();
OwnerName="Mandhara";
printprivate();
System.out.println(""+Brand+" "+Color+" "+OwnerName);
}
}
public class prog2 {
public static void main(String[] args)
{
TwoWheeler a=new TwoWheeler();
a.getData();
a.putData();
MyTwoWheeler b=new MyTwoWheeler();
}
}
import package1.*;
class TwoWheeler extends Vehicle{
private String EngineType="2-s";
protected String Brand="Y";
public String Color="Black";
public void getData()
{
EngineType="2-stroke";
Brand="Yamaha";
Color="Black";
year=88;
}
public void putData()
{
System.out.println("Year of manufacture of the twowheeler is"+year);
System.out.println("Engine type is " +EngineType+" ,Brand is "+Brand+" ,Color is "+Color);
}
void printprivate()
{
System.out.println("Accessing private variable"+ EngineType);
}
}
class MyTwoWheeler extends TwoWheeler
{
public String OwnerName;
MyTwoWheeler()
{
super();
OwnerName="Mandhara";
printprivate();
System.out.println(""+Brand+" "+Color+" "+OwnerName);
}
}
public class prog2 {
public static void main(String[] args)
{
TwoWheeler a=new TwoWheeler();
a.getData();
a.putData();
MyTwoWheeler b=new MyTwoWheeler();
}
}
prog.java
package package3;
public class prog {
}
public class prog {
}
No comments:
Post a Comment