Create Two Classes in JAVA

0
60

JAVA is truly object oriented programming language this mean you need to write Main function inside a class. Best practice in this case is to create a class only for main function and access all other class members from this class. This creates the need of creating more than one classes. In this video you will learn how to create two classes and how to run the program.

Syntax :-


class employee
  {
	  int empID=5;
	  void showEmpID()
	  {
		  System.out.println(empID);
	  }	  
   }
   class company
   {
	   public static void main(String args[])
	  {
		  employee e; // object declaration
		  e=new employee();
		  e.showEmpID();
	  }
   }
 
Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes0
No0
Previous articleJAVA tutorials for beginners
Next articleMatrix addition in JAVA
An educational consultant Vineet Agrawal is a director and founder of Solution Center, Agra. He has been providing training for last 17 years. He has trained 1000s of students of the software industry. He has been actively involved in final year projects of B.Tech. (CS /IT). The programs included in this video series are based on his experience of teaching that will help you in cracking a java interview.

Leave a Reply