 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Class declaration with one method in Java
A class declaration can contain a single method. A program that demonstrates this is given as follows:
Example
class Message {    public void messagePrint() {       System.out.println("This is a class with a single method");    } } public class Demo {    public static void main(String args[]) {       Message m = new Message();       m.messagePrint();    } }  Output
This is a class with a single method
Now let us understand the above program.
The Message class is created with a single member function messagePrint(). A code snippet which demonstrates this is as follows −
class Message {    public void messagePrint() {       System.out.println("This is a class with a single method");    } } In the main() method, an object m of class Message is created. Then messagePrint() method is called. A code snippet which demonstrates this is as follows −
public class Demo {    public static void main(String args[]) {       Message m = new Message();       m.messagePrint();    } }Advertisements
 