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.
class MyBook extends Book{
String s1;
void setTitle(String s){
this.s1 = s;
String s1 = "A tale of two cities";
}
String getTitle(){
return s1;
}
}
//Write MyBook class here
public class Main{
public static void main(String []args){
//Book new_novel=new Book(); This line prHMain.java:25: error: Book is abstract; cannot be instantiated
Scanner sc=new Scanner(System.in);
String title=sc.nextLine();
MyBook new_novel=new MyBook();
new_novel.setTitle(title);
System.out.println("The title is: "+new_novel.getTitle());
sc.close();
}
}
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 →
import java.util.*; abstract class Book{ String title; abstract void setTitle(String s); String getTitle(){ return title; } }
class MyBook extends Book{ String s1; void setTitle(String s){ this.s1 = s; String s1 = "A tale of two cities"; } String getTitle(){ return s1; } } //Write MyBook class here
public class Main{
}