Posts

Showing posts with the label javamcq's

Java MCQ's

1) Predict the output of following Java Programs. Program 1: // filename Main.java  class Test {      protected int x, y;  }  class Main {      public static void main(String args[]) {          Test t = new Test();          System.out.println(t.x + " " + t.y);      }  }  Output:  0 0 Explanation: In Java, a protected member is accessible in all classes of same package and in inherited classes of other packages. Since Test and Main are in same package, no access related problem in the above program. Also, the default constructors initialize integral variables as 0 in Java (See this GFact for more details). That is why we get output as 0 0. Program 2: // filename Test.java  class Test {      public static void main(String[] args) {          for(int i = 0; 1; i++) {              System.ou...