You are on page 1of 10

Packages

Question1

package test;

public class Foundation

private int var1;

int var2;

protected int var3;

public int var4;

public class Hello

public static void main(String[] args)

Foundation f = new Foundation();

f.var2 = 2;

f.var3 = 3;

f.var4 = 4;

System.out.println(f.var2);

System.out.println(f.var3);

System.out.println(f.var4);

Output

Questiom2

package com.wipro.automobile.ship;

public class Compartment

private double height;


private double width;

private double breadth;

public Compartment(double height, double width, double breadth)

this.height = height;

this.width = width;

this.breadth = breadth;

@Override

public String toString() {

return "Compartment [height=" + height + ", width=" + width + ", breadth=" + breadth + "]";

package com.wipro.automobile.ship;

public class Solution

public static void main(String[] args)

Compartment compartment = new Compartment(990.9, 299.8, 477.5);

System.out.println(compartment);

Output

height=990.9

width=299.8

breath=477.5

Question3

package com.automobile;

public abstract class Vehicle

public abstract String getModelName();


public abstract String getRegistrationNumber();

public abstract String getOwnerName();

package com.automobile.twowheeler;

import com.automobile.Vehicle;

public class Hero extends Vehicle

private String modelName;

private String registrationNumber;

private String ownerName;

private int speed;

public Hero(String modelName, String registrationNumber, String ownerName, int speed)

this.modelName = modelName;

this.registrationNumber = registrationNumber;

this.ownerName = ownerName;

this.speed = speed;

@Override

public String getModelName() {

return modelName;

@Override

public String getRegistrationNumber() {

return registrationNumber;

@Override

public String getOwnerName() {


return ownerName;

public int getSpeed() {

return speed;

public void radio() {

System.out.println("Accessing the radio");

package com.automobile.twowheeler;

import com.automobile.Vehicle;

public class Honda extends Vehicle

private String modelName;

private String registrationNumber;

private String ownerName;

private int speed;

public Honda(String modelName, String registrationNumber, String ownerName, int speed)

this.modelName = modelName;

this.registrationNumber = registrationNumber;

this.ownerName = ownerName;

this.speed = speed;

@Override

public String getModelName()

return modelName;
}

@Override

public String getRegistrationNumber()

return registrationNumber;

@Override

public String getOwnerName()

return ownerName;

public int getSpeed()

return speed;

public void cdplayer()

System.out.println("Accessing CD Player");

package com.automobile;

import com.automobile.twowheeler.Hero;

import com.automobile.twowheeler.Honda;

public class Test

public static void main(String[] args)

{
Hero hero = new Hero("Hero splender", "MN32MM5123", "Ritesh", 80);

System.out.println(hero.getModelName());

System.out.println(hero.getOwnerName());

System.out.println(hero.getRegistrationNumber());

System.out.println(hero.getSpeed()+" kmph");

hero.radio();

System.out.println();

Honda honda = new Honda("Honda CBZ", "N34FZ6543", "Sachin", 130);

System.out.println(honda.getModelName());

System.out.println(honda.getOwnerName());

System.out.println(honda.getRegistrationNumber());

System.out.println(honda.getSpeed()+" kmph");

honda.cdplayer();

Question4

package com.automobile;

public abstract class Vehicle

public abstract String getModelName();

public abstract String getRegistrationNumber();

public abstract String getOwnerName();

package com.automobile.fourwheeler;

import com.automobile.Vehicle;

public class Ford extends Vehicle {

private String modelName;

private String registrationNumber;


private String ownerName;

private int speed;

public Ford(String modelName, String registrationNumber, String ownerName, int speed) {

this.modelName = modelName;

this.registrationNumber = registrationNumber;

this.ownerName = ownerName;

this.speed = speed;

@Override

public String getModelName()

return modelName;

@Override

public String getRegistrationNumber()

return registrationNumber;

@Override

public String getOwnerName()

return ownerName;

public int speed()

return speed;

public void tempControl()


{

System.out.println("Accessing Temperature Controlling");

package com.automobile.fourwheeler;

import com.automobile.Vehicle;

public class Logan extends Vehicle {

private String modelName;

private String registrationNumber;

private String ownerName;

private int speed;

public Logan(String modelName, String registrationNumber, String ownerName, int speed) {

this.modelName = modelName;

this.registrationNumber = registrationNumber;

this.ownerName = ownerName;

this.speed = speed;

@Override

public String getModelName()

return modelName;

@Override

public String getRegistrationNumber()

return registrationNumber;

}
@Override

public String getOwnerName()

return ownerName;

public int speed()

return speed;

public void gps()

System.out.println("Accessing GPS");

package com.automobile;

import com.automobile.fourwheeler.Ford;

import com.automobile.fourwheeler.Logan;

public class TestFourWheeler

public static void main(String[] args)

Ford ford = new Ford("Ford Ecosport", "MP68MC6060", "Ajay Singh", 170);

System.out.println(ford.getModelName());

System.out.println(ford.getOwnerName());

System.out.println(ford.getRegistrationNumber());

System.out.println(ford.speed()+" kmph");

ford.tempControl();

System.out.println();
Logan logan = new Logan("Mahindra Logan", "M15FD5103", "Vijay Singh", 180);

System.out.println(logan.getModelName());

System.out.println(logan.getOwnerName());

System.out.println(logan.getRegistrationNumber());

System.out.println(logan.speed()+" kmph");

logan.gps();

You might also like