Tutorials for Java ,Core java ,Advance java ,oracle ,HTML, CSS, JavaScript, Java and other programming language tutorial Learn Java tutorial for beginners with examples in eclipse online. Java tutorial point for core java, servlet, jsp, struts, spring, for learning web technologies online. Content includes tutorials and references relating to HTML, CSS, JavaScript, PHP, AngularJS, SQL, Bootstrap, Node.js, and jQuery this is a website like w3school tutorialspoint etc

Search This Blog

About

Header Ads

Sunday, 8 April 2018

Multiple Classes Core Java Program

0 comments

Multiple Classes Core Java Program


//MultipleClasses.java
class A
{
}

class B
{
    static void m1()
   {
       System.out.println("B m1()");
   }
}
class C
{
    static void m2()
   {
       System.out.println("C m2()");
   }
   public static void main(String[] args)
   {
      System.out.println("C main()");
   }
}

class D
{
    static void m3()
   {
       System.out.println("D m3()");
   }
   public static void main(String[] args)
   {
      System.out.println("D main()");
      m3();
   }
    static void m4()
   {
       System.out.println("D m4()");
   }
}

class E
{
   static void m5()
  {
      System.out.println("E m5");
  }
  public static void main(String[] args)
  {
      System.out.println("E main");  
      m5();

      //m1(); CE: cannot find symbol
      B.m1();
      C.m2(); 
      D.m3();
      D.m4();

  }
}
/*
Compilation:
.\01basics>javac MultipleClasses.java
|_A.class
|_B.class
|_C.class
|_D.class
|_E.class
Execution:
.\01basics>java A
Exception in thread "main" java.lang.NoSuchMethodError: main

.\01basics>java B
Exception in thread "main" java.lang.NoSuchMethodError: main

.\01basics>java C
C main()

.\01basics>java D
D main()
D m3()

.\01basics>java E
E main()
E m5()
B m1()
C m2()
D m3()
D m4()

01 basics>javac F.java
javac: file not found: F.java

=>
\01basics>java F
Exception in thread "main" java.lang.NoClassDefFoundError: F

*/

No comments:

Post a Comment