07 | 09 | 2010
Main Menu
Affiliates
Login Form



Alexa
JoomlaWatch Stats 1.2.6 by Matej Koval
Interview Question in java on Classes, Interfaces and Methods - Page 3# Classes, Interfaces and Methods
Written by Java Guru   
Sunday, 18 May 2008 03:31
Article Index
Interview Question in java on Classes, Interfaces and Methods
Page 2# Classes, Interfaces and Methods
Page 3# Classes, Interfaces and Methods
Page 4# Classes, Interfaces and Methods
All Pages

Q. If no command line arguments are provided what will String array in main () will contain?

A: String array will be empty ie an array of size zero .(Unlike in C++ where the first argument is always the program name)

Q. What are Environment variable are to be set to run java program?

A: CLASSPATH and PATH are two variables required.

Q. Is it possible to have main method in multiple classes?

A: Yes it possible .The JVM will look for the main method only in the class whose name is specified as argument to the java executable. so there is no conflict

Q. Is it possible to have multiple main methods in a class?

A: No the program will not compile because a class cannot have more that one method with the same signature.

Q. What is Overriding?

A: When a method in subclass contains same name and arguments as that of superclass , the method in the class overrides the method in superclass.

Q. Name different type of inner class?

A: Nested top-level classes, Member classes, Local classes, Anonymous classes

Nested top-level classes:-when a class is declared within a class with static modifier. The compiler treats the class as any other top-level class. It can be accessed outside the class by classname.staticclassname.

Member classes:-member classes are define inside the body of a class along with member variables and methods. It can be used anywhere within the body of the class. To create an instance of such classes from outside, we need to use an instance of the enclosing class.

Local classes:- Local class are define inside a block of code(inside member methods or inside if loop) just like a local variable. There visibility is within the block of code they are defined .

Anonymous classes :- Anonymous classes are declared and instantiated within the same statement. They do not have names, and they can be instantiated only once.

Q. Are the imports checked for validity at compile time?

A: Yes the imports are checked for validity at compile time. If an import is found invalid then error is shown , cannot resolve symbol.

Q. When a package is imported will it’s subpakages are also imported?

A: No, we have to import the subpackages we require separately. Only the classes in that package is import eg: import org.test.*

Q. How does declaring a variable differ from defining a variable?

A: In declaration the type of variable and it’s name is mentioned .we do not initialize it. But defining means declaring the variable and initializing it.

eg:

int index; -- declaring

int index=10; --defining



Comments
Search
Only registered users can write comments!

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Monday, 26 May 2008 05:47 )