Tuesday, 1 January 2013

Multiple Classes in java source file

// siddhu vydyabhushana // 1 comment
Hi.., happy new year after 3 months of gap i came here to post a powerful feature of java ,that is
multiple classes in a java program
Actually java is a programming language which it run in a platform.

1) Take three classes as

class a() { }

class b() { }

class multiple() {}

2)write program

3)compile ,after u will get 

a.class , b.class  ,multiple.class




PROGRAM CODE: save below code as multiple.java


class a
{
a()
{
int i=10;
System.out.println("value in class a="+i);
}
}
class b
{
b()
{
int i=5;
System.out.println("value in class b="+i);
}

}// no need to declare public access specifier
public class multiple
{
public static void main(String args[])
{
a A=new a();
b B=new b();
}
}

separately we code it as
CLASS A()

class a
{
a()
{
int i=10;
System.out.println("value in class a="+i);
}
}

CLASS B()

class b
{
b()
{
int i=5;
System.out.println("value in class b="+i);
}

}

1 comment: