Java Interview Question And Answer | Java Interview Question And Answer For Fresher | Core Java Interview Question And Answare | Set 06

1.What is the argument of main() method?
 Ans: main() method accepts an array of String object as argument.

2.Can a main() method be overloaded?
 Ans: Yes. You can have any number of main() methods with different method signature and implementation in the class.

3.Can a main() method be declared final?
 Ans: Yes. Any inheriting class will not be able to have it's own default main() method.

4.Does the order of public and static declaration matter in main() method?
 Ans: No. It doesn't matter but void should always come before main().

5.What are the static fields & static Methods ?
 Ans: If a field or method defined as a static, there is only one copy for entire class, rather than one copy for each instance of class. static method cannot access non-static field or call non-static method

6.What are the Final fields & Final Methods ?
 Ans: Fields and methods can also be declared final.
         Final method: A final method cannot be overridden in a subclass.
         Final field: A final field is like a constant: once it has been given a value, it cannot be assigned to again.

7.What is user-defined exception in java ?
 Ans: User-defined expectations are the exceptions defined by the application developer which are errors related to specific application. Application Developer can define the user defined exception by inherited the Exception class as shown below. Using this class we can throw new exceptions for this we have  use throw keyword .
     
8.Can a class declared as private be accessed outside it's package?
 Ans: Not possible.

9.Can a class be declared as protected?
 Ans: A class can't be declared as protected. only methods can be declared as protected.

10.What is the access scope of a protected method?
 Ans: A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.

Previous Next


:: Click the links below for similar type Questions and answers ::

0 comments:

Post a Comment

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes