Sort by

recency

|

204 Discussions

|

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

    } `

  • + 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, khong can public--Step1 class MyBook extends Book{ // dung tu khoa extend de ke tua lop abstract Book--Step2 @Override // ghi de method setTitle voi tham so, va tao body goi s --Step3 public void setTitle(String s){ this.title = 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();
    
    }
    

    }