Java Programming Questions & Answers: part12



Software Programming : Java Programming QUESTIONS AND ANSWERS :: part12 : 1 to 5

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

1.When you run an applet, which of the following is invoked first?

The init method
The start method
The stop method
The destroy method
The applet's default constructor.

2.Analyze the following code and choose the correct answer: public class Foo { private int x; public static void main(String[] args) { Foo foo = new Foo(); System.out.println(foo.x); } }

Since x is private, it cannot be accessed from an object foo
Since x is defined in the class Foo, it can be accessed by any method inside the class without using an object. You can write the code to access x without creating an object such as foo in this code
Since x is an instance variable, it cannot be directly used inside a main method. However, it can be accessed through an object such as foo in this code
You cannot create a self-referenced object; that is, foo is created inside the class Foo
Since x is public it cannot be accessed from an object foo.

3.Which of the follows JDK command is correct to run a Java application in ByteCode.class? #186. Which of the follows JDK command is correct to run a Java application in ByteCode.class?

java ByteCode
java ByteCode.class
javac ByteCode.java
javac ByteCode
JAVAC ByteCode.

4.What is the output of the following code? public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4, 5}; increase(x); int[] y = {1, 2, 3, 4, 5}; increase(y[0]); System.out.println(x[0] + " " + y[0]); } public static void increase(int[] x) { for (int i = 0; i < x.length; i++) x[i]++; } public static void increase(int y) { y++; } }

0 0
1 1
2 2
2 1
1 2.

5.What would be the result while attempting to compile and run the following code? public class Test { public static void main(String[] args) { double[] x = new double[]{1, 2, 3}; System.out.println("Value is " + x[1]); } }

The program has a syntax error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by {1, 2, 3}.
The program has a syntax error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[3]{1, 2, 3};
The program has a syntax error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[]{1.0, 2.0, 3.0};
The program compiles and runs fine and the output "Value is 1.0" is printed
The program compiles and runs fine and the output "Value is 2.0" is printed.

More Java Programming QUESTIONS AND ANSWERS available in next pages

    Health is the greatest gift, contentment is the greatest wealth -Buddha
Trust because you are willing to accept the risk, not because it’s safe or certain