Is it possible to write JAVA program without including any
of the packages,such as "import java.io.*";
bcoz I instantly wrote a code without "import..." statement
and runned the program on command Line & it worked.
the code is:
class Person
{
String name;
int age;
Person(String s,int a)
{
name = s;
age = a;
}
accept()
{
System.out.println(name+"Hi!!!!!");
System.out.println(age);
}
}
class Demo
{
public static void main(Strings args[])throws
IOException
{
String name = args[0];
int age = Integer.parseInt(args[1]);
Person p = new Person(name,age);
p.accept();
}
}
Answer Posted / appa
In main method "Strings" throws exception nd import is
necessary for above code bcz IOException is Used,
If throws is removed it will execute for sure But at cmd
line if no values are passed then IndexOutOfBoundsException
is raised, so at cmd line u have to pass the values
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is a platform?
What are basic data types?
Why does my function print none?
What is a local, member and a class variable?
Why does java not support pointers?
Can You Have Virtual Functions In Java?
Does java allow overriding static methods ?
What are computer functions?
Can we use string in the switch case?
What are the Main functions of Java?
Explain the scope or life time of class variables or static variables?
What is anti pattern in java?
What is an example of a boolean?
What is the difference between synchronized and synchronized block?
How can we achieve thread safety in java?