We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.Scanner;abstractclassBook{Stringtitle;abstractvoidsetTitle(Strings);StringgetTitle(){returntitle;}}classMyBookextendsBook{// Implementing the abstract method setTitlevoidsetTitle(Strings){this.title=s;}}publicclassMain{publicstaticvoidmain(String[]args){// Creating an instance of MyBookMyBookmyBook=newMyBook();// Reading the title from inputScannerscanner=newScanner(System.in);Stringtitle=scanner.nextLine();scanner.close();// Setting the title using the setTitle methodmyBook.setTitle(title);// Printing the titleSystem.out.println("The title is: "+myBook.getTitle());}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Abstract Class
You are viewing a single comment's thread. Return to all comments →