Ask Question
9 October, 17:02

Create a class 'ProblemSolution' with following characteristics A public method 'solution' without parameters and return type is int. Create object of class 'Student' inside 'solution' method and return the value of ""rollNumber"" from the class 'Student'.

+2
Answers (1)
  1. 9 October, 19:11
    0
    The program to this question as follows:

    Program:

    class Student / /defining class student

    {

    int rollNumber=1001; / /defining integer variable rollnumber and assign value

    int value () / /defining method value

    {

    return rollNumber; / /return value

    }

    }

    public class ProblemSolution extends Student / /defining class problemSolution that inherits Student

    {

    int solution () / /defining method solution

    {

    Student stu=new Student (); / /creating student class object

    return stu. value (); / /call function using return keyword

    }

    public static void main (String ax[]) / /defining main method

    {

    int result; / /defining integer variable result

    ProblemSolution ps=new ProblemSolution (); / /creating class object

    result=ps. solution (); / /holding value of solution function

    System. out. println ("rollNumber value is: "+result); / /print value

    }

    }

    Output:

    rollNumber value is: 1001

    Explanation:

    In the above java code two-class "Student and ProblemSolution" is defined, in which student class an integer variable rollNumber is defined, that holds a value "1001", and inside this class, a method "value" is defined, that return above variable value.

    In the next step, class "ProblemSolution" is defined, that inherits the student class, inside this class two method "solution and the main method" is defined. Inside the solution method, the student class object is created and this method uses the return keyword to call the student class method "value". In the main method, an integer variable "result" is defined, which holds its method "solution" value and uses print function to print its value.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Create a class 'ProblemSolution' with following characteristics A public method 'solution' without parameters and return type is int. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers