Java examples for Object Oriented Design:Abstract Class
Create abstract class and extend it to create another class
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String title = sc.nextLine(); String author = sc.nextLine(); int price = sc.nextInt(); Book new_novel = new MyBook(title, author, price); new_novel.display(); }//from w ww . j a v a2 s . co m } abstract class Book { String title; String author; Book(String t, String a) { title = t; author = a; } abstract void display(); } class MyBook extends Book { private int price; MyBook(String title, String author, int price) { super(title, author); this.price = price; } @Override void display() { System.out.println("Title: " + this.title); System.out.println("Author: " + this.author); System.out.println("Price: " + this.price); } }