Delivered by FeedBurner

Core Java Interview Questions For Selenium WebDriver - Part 3

Part 3

11 : Why main method is static?

Answer : As we know, We can access static stuff without creating object of class. Because of static keyword with main method, Java virtual machine can directly call it without creating object of class. This way it will provide kind of root to start execution of program.

12 : What is method overloading?

Answer : Method overloading is ability to create multiple methods with same in same class but with different signatures (different input parameters and types). Method names will be same but parameters will be different for all overloaded methods.

13 : What is constructor overloading?

Answer : Same as method overloading, Single class can have multiple constructors with same name as class name but all have different signatures (different input parameters and types) is called constructor overloading. READ MORE about constructor overloading.

14 : Can we override static methods?

Answer : We can declare static method with same signature in subclass but it will not behave as overridden method. So answer is No.. We can not override static methods as they are part of  class not object.. You can override static methods but output will be different than the expected.

15 : How to reverse string in java?

Answer : StringBuffer class has a method called reverse(). We can use it to reverse the string.
Example :

public static void main(String[] args) {
// buffer string using StringBuffer class.
StringBuffer a = new StringBuffer("I like java very much.");
// use reverse() method to reverse string

No comments:

Post a Comment