Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Java Variable
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
class Rextester { private String name; private int age; // In addition to having the side-effect of setting the attributes in question, // the setters return "this" (the current Person object) to allow for further chained method calls. public Rextester setName(String name) { this.name = name; return this; } public Rextester setAge(int age) { this.age = age; return this; } public void introduce() { System.out.println("Hello, my name is " + name + " and I am " + age + " years old."); } // Usage: public static void main(String[] args) { Rextester person = new Rextester(); // Output: Hello, my name is Peter and I am 21 years old. person.setName("Peter").setAge(21).introduce(); } }
[
+
]
Show input
Compilation time: 0.73 sec, absolute running time: 0.14 sec, cpu time: 0.07 sec, memory peak: 31 Mb, absolute service time: 0.88 sec
edit mode
|
history
|
discussion
Hello, my name is Peter and I am 21 years old.