Java Programming Questions & Answers: part12



Software Programming : Java Programming QUESTIONS AND ANSWERS :: part12 : 11 to 15

Following Software Programming language Entrance Multiple choice objective type questions and answers will help you in Software Programming 2024 examinations :

11.What is the printout of the third println statement in the main method? public class Foo { int i; static int s; public static void main(String[] args) { Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); } public Foo() { i++; s++; } }

f3.i is 1 f3.s is 1
f3.i is 1 f3.s is 2
f3.i is 1 f3.s is 3
f3.i is 3 f3.s is 1
f3.i is 3 f3.s is 3.

12.What is the printout of the second println statement in the main method? public class Foo { int i; static int s; public static void main(String[] args) { Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); } public Foo() { i++; s++; } }

f2.i is 1 f2.s is 1
f2.i is 1 f2.s is 2
f2.i is 2 f2.s is 2
f2.i is 2 f2.s is 1
f2.i is 0 f2.s is 1.

13.What is wrong in the following code? class TempClass { int i; public void TempClass(int j) { int i = j; } } public class C { public static void main(String[] args) { TempClass temp = new TempClass(2); } }

The program has a compilation error because TempClass does not have a default constructor
The program has a compilation error because TempClass does not have a constructor with an int argument
The program compiles fine, but it does not run because class C is not public
The program compiles and runs fine
All of the above.

14.What code may be filled in the blank without causing syntax or runtime errors? public class Test { java.util.Date date; public static void main(String[] args) { Test test = new Test(); System.out.println(_________________); } }

Test.date
Date
Test.date.toString()
Date.toString()
Date.test.

More Java Programming QUESTIONS AND ANSWERS available in next pages

    Health is the greatest gift, contentment is the greatest wealth -Buddha
Too many of us are not living our dreams because we are living our fears.- Les Brown