Kerja6_2

2
/**  * @(#)Vehicle.java  *  *  * @MUHAMAD SHAFIQ AMINI BIN MOHD ZANI  * @1139015  * @version 1.00 2012/8/30  */  public class Vehicle { int noOfTyres; // no of tyres private boolean accessories; // check if accessorees present or not protected String brand; // Brand of the car private static int counter; // No of Vehicle objects created Vehicle() { System.out.println("Co nstructor of the Super class called"); noOfTyres = 5; accessories = true; brand = "X"; counter++; } public void switchOn() { accessories = true; } public void switchOff() { accessories = false; } public boolean isPresent() { return accessories; } private void getBrand() { System.out.println("Ve hicle Brand: " + brand); } public static void getNoOfVehicles() { System.out.println("Number of Vehicles: " + counter); } } class Car extends Vehicle {  private int carNo = 10; public void printCarInfo() { System.out.println("Ca r number: " + carNo); System.out.println("No of Tyres: " + noOfTyres); // Inherited. System.out.println("accessories: " + isPresent()); // Inherited.  System.out.println("Br and: " + brand); // Inherited.  getNoOfVehicles(); // Inherited. } } class VehicleDetails { // (3) public static void main(String[] args) { new Car().printCarInfo(); } } --------------------Co nfiguration: <Default>-------------------- Constructor of the Super class called Car number: 10 No of Tyres: 5 accessories: true

Transcript of Kerja6_2

Page 1: Kerja6_2

7/23/2019 Kerja6_2

http://slidepdf.com/reader/full/kerja62 1/2

/** * @(#)Vehicle.java * * * @MUHAMAD SHAFIQ AMINI BIN MOHD ZANI * @1139015 * @version 1.00 2012/8/30 */ 

public class Vehicle {int noOfTyres; // no of tyresprivate boolean accessories; // check if accessorees present or notprotected String brand; // Brand of the carprivate static int counter; // No of Vehicle objects createdVehicle() {

System.out.println("Constructor of the Super class called");noOfTyres = 5;accessories = true;brand = "X";counter++;

}public void switchOn() {

accessories = true;

}public void switchOff() {accessories = false;

}public boolean isPresent() {

return accessories;}private void getBrand() {

System.out.println("Vehicle Brand: " + brand);}public static void getNoOfVehicles() {

System.out.println("Number of Vehicles: " + counter);}

}

class Car extends Vehicle {  private int carNo = 10;

public void printCarInfo() {System.out.println("Car number: " + carNo);System.out.println("No of Tyres: " + noOfTyres); // Inherited.System.out.println("accessories: " + isPresent()); // Inherited.

  System.out.println("Brand: " + brand); // Inherited.  getNoOfVehicles(); // Inherited.

}}class VehicleDetails { // (3)

public static void main(String[] args) {new Car().printCarInfo();

}}--------------------Configuration: <Default>--------------------Constructor of the Super class calledCar number: 10No of Tyres: 5accessories: true

Page 2: Kerja6_2

7/23/2019 Kerja6_2

http://slidepdf.com/reader/full/kerja62 2/2

Brand: XNumber of Vehicles: 1

Process completed.