JAVA LAB-1 Content
2) How to access normal Variable and Static Variable?
3) How to access Normal Function and Static Function?
4) How to add multiple Class in same program?
Common Program
class C
{
//Class without main()
static int k=20;
}
class A
{
//static variable can be accessed with Class Name
static int i=10;
//Normal Variable
int j=15;
public static void main(String args[])
{
//Print First Argument
System.out.println("String - 1 "+args[0]);
// How to Concatenate multiple string using +
System.out.println(" i = " + i + " String - 2" +args[1]);
}
}
class B
{
public static void main(String args[])
{
//Accessing variable of Class A using anonymous Object
System.out.println(" J = "+new A().j);
//Declaring Array of String
String s[]={"abc","def"};
//Calling main function of Class A with Parameter
A.main(s);
//Accessing static variable of Class C
System.out.println(" C = "+C.k);
}
}
class D
{
public static void main(String args[])
{
//Calling main()
main();
}
//Overloading main()
public static int main()
{
System.out.println("Class D");
return 0;
}
}
class E
{
public static void main(String args[])
{
//Calling All main()
A.main(new String[2]);
B.main(new String[2]);
D.main(new String[2]);
}
}
How to Run & Compile JAVA Program ?
Compile :
Filepath > javac filename.java
Run :
Filepath > java classfilename
No comments:
Post a Comment