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.
// Implement the body in the child class
abstract void setTitle(String s);
String getTitle() {
return title;
}
}
class MyBook extends Book {
void setTitle(String s) {
super.title = s;
}
}
public class Solution {
public static void main(String[] args) {
Book bookTitle = new MyBook();
Scanner scan = new Scanner(System.in);
String title = scan.nextLine();
bookTitle.setTitle(title);
System.out.println("The title is: " +
bookTitle.getTitle());
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Java Abstract Class
You are viewing a single comment's thread. Return to all comments →
abstract class Book { String title;
}
class MyBook extends Book {
}
public class Solution { public static void main(String[] args) {
}
}