Skip to main content
Progzoo.net
Tutorials
Guides
Edit
Java
C#
C++
Perl
PHP
Python
Ruby
VB
Hide Sidebar
Show Sidebar
<Progzoo Sections>
ProgZoo
Tutorials
How to...
Assessments
Help
<Other>
To do list
Recent changes
Random page
Personal
Log in / create account
Views
Article
Discussion
View source
History
Toolbox
What links here
Related changes
Upload file
Special pages
Printable version
Define a Class
From Progzoo
Top Ten Tips
Hello World
Convert to Number
Read Text File
Sum an Array
Count 0 to 9
Hash Table
Regular Expression
Read Database
Read XML
Define a Class
The class Person has
a constructor:
Person
attributes
n, w
and
h
a method:
bmi
.
class Person{ String n; double w,h; public Person(String name,double weight,double height){ n=name;w=weight;h=height; } public double bmi(){ return w/h/h; } } public class Hello{ public static void main(String argv[]) { Person p = new Person("andrew",99,1.8); System.out.println(p.bmi()); System.out.println(p.n); } }
[
Font
] [
Default
] [
Show
] [
Resize
] [
History
] [
Profile
]
test text