Skip to content

Commit 7de6f89

Browse files
authored
Java Abstract Class
HackerRank Java Abstract Class.
1 parent 1e60221 commit 7de6f89

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Java Abstract Class

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.util.*;
2+
abstract class Book{
3+
String title;
4+
abstract void setTitle(String s);
5+
String getTitle(){
6+
return title;
7+
}
8+
9+
}
10+
class MyBook extends Book{
11+
void setTitle(String s)
12+
{
13+
title=s;
14+
}
15+
}
16+
//Write MyBook class here
17+
18+
public class Main{
19+
20+
public static void main(String []args){
21+
//Book new_novel=new Book(); This line prHMain.java:25: error: Book is abstract; cannot be instantiated
22+
Scanner sc=new Scanner(System.in);
23+
String title=sc.nextLine();
24+
MyBook new_novel=new MyBook();
25+
new_novel.setTitle(title);
26+
System.out.println("The title is: "+new_novel.getTitle());
27+
sc.close();
28+
29+
}
30+
}

0 commit comments

Comments
 (0)