- /*
- Java Class example.
- This Java class example describes how class is defined and being used
- in Java language.
- Syntax of defining java class is,
- <modifier> class <class-name>{
- // members and methods
- }
- */
- public class JavaClassExample{
- /*
- Syntax of defining memebers of the java class is,
- <modifier> type <name>;
- */
- private String name;
- /*
- Syntax of defining methods of the java class is,
- <modifier> <return-type> methodName(<optional-parameter-list>) <exception-list>{
- ...
- }
- */
- public void setName(String n){
- //set passed parameter as name
- name = n;
- }
- public String getName(){
- //return the set name
- return name;
- }
- //main method will be called first when program is executed
- public static void main(String args[]){
- /*
- Syntax of java object creation is,
- <class-name> object-name = new <class-constructor>;
- */
- JavaClassExample javaClassExample = new JavaClassExample();
- //set name member of this object
- javaClassExample.setName("Visitor");
- // print the name
- System.out.println("Hello " + javaClassExample.getName());
- }
- }
- /*
- OUTPUT of the above given Java Class Example would be :
- Hello Visitor
- */
Welcome to the world of Java examples, organized by categories and Java packages. Java examples (Java sample source code) help to understand functionality of various Java classes and methods as well as various programming techniques in a simple way, which is otherwise very hard to learn by reading tutorials or Java API. So start exploring...
Sunday, November 27, 2011
Java Class example.
Subscribe to:
Post Comments (Atom)
How to find the most appropriate Keywords?
🔍 Step 1: Understand Your Business and Audience Define your products, services, or content . Identify your target audien...
-
/* Pause Thread Using Sleep Method Example This Java example shows how to pause currently running thread using sleep method of Jav...
-
/* Java String split example. This Java String split example describes how Java String is split into multiple Java String objects. */ ...
-
// File Name GreetingClient.java import java.net.*; import java.io.*; public class GreetingClient { public static void main(String [] ...
No comments:
Post a Comment