Java Abstract Class
Java Abstract Class
+ 0 comments class MyBook extends Book { void setTitle(String s) { title=s;
}
}
+ 0 comments here is the simple solution https://github.com/csennn/java_abstract_class/blob/main/codes
+ 0 comments import java.io.; import java.util.;
public class Solution {
public static void main(String []args){ //Book new_novel=new Book(); Abstract cass cannot be instantiated like this 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()); }
}
abstract class Book{ String title; abstract void setTitle(String s); String getTitle(){ return title; } }
class MyBook extends Book{ void setTitle(String s){ title=s; } }
+ 0 comments Here is problem solution - https://thecscience.com/hackerrank-java-abstract-class-problem-solution.html
+ 0 comments The problem and what we need to do is defined nicely. As the abstract class is given we have to create MyBooks class that extends the abstract class. Now, as this is a child class, it will inherit all the properties of super class. So, I've just defined the body of the setTitle method here. And it's all.
//Write MyBook class here class MyBook extends Book{ void setTitle(String s){ title = s; } }
Sort 148 Discussions, By:
Please Login in order to post a comment