Sort by

recency

|

213 Discussions

|

  • + 0 comments

    This helps you understand the concept of Abstract classes in java. The abstarct classes/methods acts a skeleton for the class that you are about to write.

    import java.io.*;
    import java.util.*;
    
    abstract class Book{
        String title;
        abstract void setTitle(String s);
        String getTitle(){
            return title;
        }
    }
    
    //You can see that I have made another class which extends the Book class and its methods
    //I have to go ahead and define the setTitle() method as well since it is abstract.
    
    class Test extends Book{
        void setTitle(String title){
            this.title = title;
        }
    }
    
    public class Solution {
    	//You need to call the Test class here by creating an object for it.
        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);
            Test test = new Test();
            String s = sc.nextLine();
            sc.close();
            test.setTitle(s);
            System.out.println("The title is: "+test.getTitle());
        }
    }
    

    Hope the solution was helpful.

  • + 0 comments

    A Java abstract class is a class that can't be instantiated. That means you cannot create new instances of an abstract class. It works as a base for subclasses. You should learn about Java Inheritance before attempting this challenge.

    Following is an example of abstract class:

    abstract class Book{ String title; abstract void setTitle(String s); String getTitle(){ return title; } } If you try to create an instance of this class like the following line you will get an error:

    Book new_novel=new Book(); You have to create another class that extends the abstract class. Then you can create an instance of the new class.

    Notice that setTitle method is abstract too and has no body. That means you must implement the body of that method in the child class.

    In the editor, we have provided the abstract Book class and a Main class. In the Main class, we created an instance of a class called MyBook. Your task is to write just the MyBook class.

    Your class mustn't be public.

    Sample Input

    A tale of two cities Sample Output

    The title is: A tale of two cities Language Java 7 More 191011121314151617181920 import java.util.*; abstract class Book{ String title; abstract void setTitle(String s); String getTitle(){ return title; } }

    // MyBook class extending the abstract Book class class MyBook extends Book { // Implement the abstract setTitle method @Override void setTitle(String s) { this.title = s; } }

    Line: 9 Col: 1

    Test against custom input BlogScoring

  • + 0 comments

    Using Java

    class MyBook extends Book

    {

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

    }

  • + 0 comments

    It allows you to define abstract methods (methods without implementation) that must be implemented by its subclasses, as well as concrete methods (fully defined methods) that subclasses can reuse. www winbuzz com

  • + 0 comments

    Java abstract classes are powerful tools to design flexible and reusable code. They allow developers to define a blueprint for related classes, enforcing specific behaviors (via abstract methods) while sharing common functionality (via concrete methods). Cricbet99 Green