SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

Java Questions And Answers For Selenium

Part 9

41 : In java, What is return type of main method?
Answer : Main method doesn't have any return type. It is void.

42 : Can We Overload main method in java?
Answer : Yes, Java class can have any number of main methods so it is possible to overload main method. But when you run program, It will not execute overloaded main method. Always It will execute only public static void main(String[] args) method.

43 : Can we declare class as protected?
Answer : No, You can not declare class as protected.

44 : Write a program to remove given character from string.
Answer : Program to remove given character from string is as bellow.

package JAVAExamples;

public class RemoveChar {
 
 public static String removeChar(String str, char c) {
     if (str == null)
         return null;
     return str.replaceAll(Character.toString(c), "");
 }
 
 public static void main(String[] args) {
  System.out.println(removeChar("chicago", 'c'));
 }
}

45 : How to convert string from upper to lower and lower to upper case?
Answer : You can use toUpperCase and toLowerCase methods to convert string from lower to upper and upper to lower case.

No comments:

Post a Comment