-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerrankJava0051.java
More file actions
43 lines (32 loc) · 1.33 KB
/
HackerrankJava0051.java
File metadata and controls
43 lines (32 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
public class HackerrankJava0051 {
public static void main(String[] args) {
// Java Abstract Class
// https://www.hackerrank.com/challenges/java-abstract-class/problem?isFullScreen=true
// 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();
}
}
abstract class Book {
String title;
abstract void setTitle(String s);
String getTitle() {
return title;
}
}
// -------------------------------------------------------------------------------------------------
// --- You need to add this lines for solution hackerrank provides all other lines for challange ---
// -------------------------------------------------------------------------------------------------
class MyBook extends Book {
void setTitle(String title) {
super.title = title;
}
}
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------