61-70 Flashcards

1
Q

A person says that he compiled a java class successfully without even having a main method in it? Is it possible?

A

main method is an entry point of Java class and is required for execution of the program however; a class gets compiled successfully even if it doesn’t have a main method. It can’t be run though.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can we call a non-static method from inside a static method?

A

Non-Static methods are owned by objects of a class and have object level scope and in order to call the non-Static methods from a static block (like from a static main method), an object of the class needs to be created first. Then using object reference, these methods can be invoked.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two environment variables that must be set in order to run any Java programs?

A

Java programs can be executed in a machine only once following two environment variables have been properly set:

PATH variable
CLASSPATH variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can variables be used in Java without initialization?

A

In Java, if a variable is used in a code without prior initialization by a valid value, program doesn’t compile and gives an error as no default value is assigned to variables in Java.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can a class in Java be inherited from more than one class?

A

In Java, a class can be derived from only one class and not from multiple classes. Multiple inheritances is not supported by Java.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can a constructor have different name than a Class name in Java?

A

Constructor in Java must have same name as the class name and if the name is different, it doesn’t act as a constructor and compiler thinks of it as a normal method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can a dead thread be started again?

A

In java, a thread which is in dead state can’t be started again. There is no way to restart a dead thread.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly