Java Programming Interview Questions

Part 7

31 : What is default value of local variable.
Answer : There is not any default value of local variable. You must have to initialize it. View more details on local variables in java.

32 : Java support constructor inheritance?
Answer : No, Constructor inheritance is not supported in java. View more details on constructor in java.

33 : Which is super class of all other classes in java?
Answer : java.lang.Object is  super class of all other classes in java.

34 : What is Encapsulation?
Answer : Encapsulation is process of packing code and data together In to a single Unit. View more details on Encapsulation in java.

35 : Write a program to reverse a string without using reverse function.
Answer : Program to reverse a string without using reverse function in java is as bellow.

package JAVAExamples;

public class StringReverse {
 public static void main(String[] args) {  
  //String to reverse.
  String str = "This Is String.";
  String revstring = "";

  for (int i = str.length() - 1; i >= 0; --i) {
   //Start getting characters from end of the string.
   revstring += str.charAt(i);
  }

  System.out.println(revstring);
 }
}

Output : .gnirtS sI sihT

2 comments:

  1. In solution for 35:
    println can be replaced by print for better visual experience

    ReplyDelete
  2. Thanks for such questions. These are really helpful for selenium interview pov.

    ReplyDelete