- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a class and object in JShell in Java 9?
JShell is a new java shell tool released in java 9. It is the first official REPL (Read-Evaluate-Print-Loop) application. This tool helps in executing and evaluating simple java programs and logics such as statements, loops, expressions, and etc. Java REPL provides a simple programming environment in the command prompt. It can read the input, evaluate it and print the output.
In the below example we can able to create a class and object in JShell using command prompt.
Example
jshell> class Employee { ...> private String name; ...> Employee(String name) { ...> this.name=name; ...> } ...> String getName() { ...> return name; ...> } ...> void setName(String name) { ...> this.name=name; ...> } ...> } | created class Employee
Example
jshell> Employee emp = new Employee("Adithya") emp ==> Employee@4b952a2d jshell> emp.getName() $3 ==> "Adithya"
Advertisements
To Continue Learning Please Login
Login with Google