How to create a Class in JShell of Java 9 Last Updated : 14 Feb, 2020 Comments Improve Suggest changes Like Article Like Report JShell is an interactive Java Shell tool, it allows us to execute Java code from the shell and shows output immediately. JShell is a REPL (Read Evaluate Print Loop) tool and runs from the command line. Jshell have the facility to create a class by which all the efforts can be reduced to write a whole Java code to check the class is working properly or not. A class contains different methods and variables according to user requirements but the program doesn't work due to some errors. But with the help of JShell, this can be resolved more efficiently and can be less time-consuming. Example: In this example, class A is created successfully and one can call the class methods by creating an object of class A. Shell C:\Windows\SysWOW64>jshell | Welcome to JShell -- Version 13.0.1 | For an introduction type: /help intro jshell> class A{ ...> int x; ...> int y; ...> void get(int a, int b) ...> { ...> x=a; ...> y=b; ...> } ...> void show() ...> { ...> System.out.println("sum="+(x+y)); ...> } ...> } | created class A In this example, due to ';', an error occurs and this can be solved it easily because the line of code is small and easy. Shell jshell> class A{ ...> int x; ...> int y; ...> void get(int a, int b) ...> { ...> x=a; ...> y=b; ...> } ...> void show(); ...> { ...> System.out.println("sum="+(x+y)); ...> } ...> } | Error: | missing method body, or declare abstract | void show(); | ^----------^ Example to access the methods of the class: Shell jshell>A a=new A(); a ==> A@42dafa95 jshell>a.get(10, 20); jshell>a.show(); sum=30 In the above examples, the objects of class A is created and denoted by 'a' and we call the get and show methods. We can also override the methods of class A. After overriding the methods, a message will be displayed that "the method is modified" and now we can call the modified methods and get the answers. Shell jshell> void show(); ...> { ...> System.out.println("sum="+(x-y)); ...> } | modified method show(int, int) Comment More infoAdvertise with us Next Article How to create a Class in JShell of Java 9 S sanjanagupta16042001 Follow Improve Article Tags : Java Algorithms Technical Scripter Linux-Unix DSA Technical Scripter 2019 +2 More Practice Tags : AlgorithmsJava Similar Reads How to Create Custom Class in Java? Class is the collection of objects. Class is not a real-world entity it is just only templates and prototypes or blueprints. Class does not occupy memory. We can write a custom class as per our choice for an illustration purpose a sample is shown in the program below as a helper class. Example: Java 2 min read How to Create Classes in Android Studio? In Android during the project development most of the time there is a need for classes in the projects. For example, in the case of CRUD operation, we need a model class to insert and retrieve data. Also to hold the info in our custom view we need to create a getter setter class. So basically in and 3 min read How to Execute a .class File in Java? A Java Class file is a compiled java file. It is compiled by the Java compiler into bytecode to be executed by the Java Virtual Machine. Step #1: Compile the .java File Open Terminal (Mac) or Command Prompt (Windows). Navigate to the folder containing the java file and type the following command to 1 min read How to Add JAR file to Classpath in Java? JAR is an abbreviation of JAVA Archive. It is used for aggregating multiple files into a single one, and it is present in a ZIP format. It can also be used as an archiving tool but the main intention to use this file for development is that the Java applets and their components(.class files) can be 4 min read Java | How to create your own Helper Class? In Java, a Helper class is a class that contains useful methods which make common tasks easier, like error handling, checking input, etc. This class intends to give a quick implementation of basic functions so that the programmers do not have to implement them again and again. This class is easy to 7 min read Like