Lab 09 Inheritance2
Lab 09 Inheritance2
//abstract method
public abstract void work();
@Override
public String toString(){
return "Name="+this.name+"::Gender="+this.gender;
}
@Override
public void work() {
if(empId == 0){
System.out.println("Not working");
}else{
System.out.println("Working as employee!!");
}
}
}
2. Lab Task 02 (Experimenting for Default Values of Instance Variables)
Implement a class Test and add 9 different data members in that class for each data type namely
(byte, short, int, long, float, double, boolean, char, String). Now in your main class, create an
object of the Test class and print the values of data members of that object. Now observe with
what values the object will be initialized by default.
// Constructor
public Test(byte aByte, short aShort, int anInt, long aLong, float aFloat, double aDouble,
boolean aBoolean, char aChar, String aString) {
this.aByte = aByte;
this.aShort = aShort;
this.anInt = anInt;
this.aLong = aLong;
this.aFloat = aFloat;
this.aDouble = aDouble;
this.aBoolean = aBoolean;
this.aChar = aChar;
this.aString = aString;
return aByte;
this.aByte = aByte;
3. Lab Task 3 A class called Account, which models a bank account of a customer, is designed
as shown in the following class diagram. The methods credit(amount) and debit(amount) add
or subtract the given amount to the balance. The method transferTo(anotherAccount,
amount) transfers the given amount from this Account to the given anotherAccount. Write
the Account class.
4. Task 4: write the codes for all the classes as shown in the class diagram.
5. Lab task 5: Abstract Superclass Shape and Its Concrete Subclasses
Shape is an abstract class containing 2 abstract methods: getArea() and getPerimeter(), where
its concrete subclasses must provide its implementation. All instance variables shall have
protected access, i.e., accessible by its subclasses and classes in the same package
In this exercise, Shape shall be defined as an abstract class, which contains:
Two protected instance variables color(String) and filled(boolean). The protected variables
can be accessed by its subclasses and classes in the same package. They are denoted with
a '#' sign in the class diagram.
Getter and setter for all the instance variables, and toString().
Two abstract methods getArea() and getPerimeter() (shown in italics in the class diagram).
The
subclasses Circle and Rectangle shall override the abstract methods getArea() and getPerimeter()
and provide the proper implementation. They also override the toString().