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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Java
  3. Object Oriented Programming
  4. Java Abstract Class
  5. Discussions

Java Abstract Class

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 153 Discussions, By:

recency

Please Login in order to post a comment

  • ha_huynh_84
    2 weeks ago+ 0 comments
    class MyBook extends Book{
        @Override
        public void setTitle(String s){
            this.title = s;
        }
    }
    
    0|
    Permalink
  • isurya834
    4 weeks ago+ 0 comments

    import java.util.*; abstract class Book{ String title; abstract void setTitle(String s); String getTitle(){ return title; } }

    //Write MyBook class here class MyBook extends Book{ public void setTitle(String s){ title=s; // System.out.println("The title is: "+s); } public String getTitle(){ return title; // System.out.println("The title is: "+s); } }

    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();
    
    }
    

    }

    -2|
    Permalink
  • hsandip640
    1 month ago+ 0 comments

    Here's Simple Java.8 Solution :

    class MyBook extends Book{ @Override void setTitle(String s) { title = s; } }

    -3|
    Permalink
  • eradehanjake
    1 month ago+ 0 comments

    import java.util.*; abstract class Book{ String title; abstract void setTitle(String s); String getTitle(){ return title; } } class MyBook extends Book{

    @Override
    void setTitle(String s) {
        this.title = s;
    }
    

    } //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();
    
    }
    

    }

    -1|
    Permalink
  • vshrwick
    2 months ago+ 1 comment
    //This code runs for all the test cases
    import java.io.*;
    import java.util.*;
    
    abstract class Book{
        String title;
        abstract void setTitle(String s);
        String getTitle(){
            return title;
        }
    }
    
    class bookextend extends Book
    {
        void setTitle(String s)
        {
            super.title = s;
        }
        String titlefinal(String s)
        {
            setTitle(s);
            return super.title;
        }
    }
    
    public class Solution {
    
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner sc = new Scanner(System.in);
            String title = sc.nextLine();
            
            bookextend b1 = new bookextend();
            
            System.out.println("The title is: "+b1.titlefinal(title));
        }
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy