Sort by

recency

|

205 Discussions

|

  • + 0 comments

    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 scan = new Scanner(System.in);
        MyBook myBook = new MyBook();
        String title = scan.nextLine();
        myBook.setTitle(title);
        System.out.println("The title is: "+myBook.getTitle());
    }
    

    }

    abstract class Book{ String title; abstract void setTitle(String s); String getTitle(){ return title; } }

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

  • + 0 comments

    abstract class Book { String title;

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

    }

    }
    

    }

  • + 0 comments

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

  • + 0 comments
    class MyBook extends Book{
        void setTitle(String s){
            super.title=s;
        }
            
        }
    
  • + 0 comments

    `Optimal solution for this problem | Easy to Understand

    abstract class Book{
       abstract void setBooktitle(String s);
    }
    class MyBook extends Book{
        @Override
        void setBooktitle(String s){
            System.out.println("The title is: " + s);
        }
    }
    
    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 str = sc.nextLine();
            MyBook book = new MyBook();
            book.setBooktitle(str);
    
        sc.close();
    }
    

    } `