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 the access scope of a protected method?
How many times finalize method will be invoked? Who invokes finalize() method in java?
Can we have 2 main methods in java class?
Can we sort a map in java?
You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain
How do you reverse a list?
Can list contain null in java?
How do you square a number in java?
What is the use of singleton class?
Can a abstract class be defined without any abstract methods?
What is the function of static in java?
Why to use nested classes in java?
What is flush buffer?
Is singleton class thread safe?
What is meant by interface?