Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////// super-class Book
- public class Book {
- String title;
- double price;
- Book(String newtitle){
- title=newtitle;
- }
- public String getTitle(){
- return title;
- }
- public double getPrice(){
- return price;
- }
- public void setPrice(double newPrice){
- price=newPrice;
- }
- }
- //////// sub-class Fiction
- public class Fiction extends Book {
- public Fiction(String fiction){
- super(fiction);
- setPrice();
- }
- public void setPrice(){
- super.price= 24.99;
- }
- }
- //////// sub-class nonFiction
- public class nonFiction extends Book{
- public nonFiction(String nonfiction){
- super(nonfiction);
- setPrice();
- }
- public void setPrice(){
- super.price = 37.99;
- }
- }
- //////// class tester/usage/implementation
- // bit.ly/oopkerul
- // LAB4
- public class useBook {
- public static void main(String[]args){
- nonFiction obj1=new nonFiction("Sejarah SPM");
- Fiction obj2=new Fiction("Armagedon");
- System.out.println(
- "The title is "+obj1.getTitle()+
- " and the price is "+obj1.getPrice());
- System.out.println(
- "The title is "+obj2.getTitle()+
- "and the price is "+obj2.getPrice());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment