Java Programming Questions & Answers: part11

Software Programming : Java Programming QUESTIONS AND ANSWERS :: part11 : 6 to 10

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

6.Consider the following program while noting the missing variable declaration indicated by ?????? : in the class Tree. class Tree { ??????Tree() { treeNo++; System.out.println("Tree "+ treeNo + " is created!"); } } public class Variable{ public static void main(String[] args) { Tree t1 = new Tree(); Tree t2 = new Tree(); Tree t3 = new Tree(); } } The output of the above program should turn out to be as shown below: Tree 1 is created! Tree 2 is created! Tree 3 is created! Select from among the following the correct variable declaration required in the class Tree to get the above output on the console:

int static treeNo = 0;
int treeNo;
static int treeNo;
static final int treeNo;
int treeNo = 0;

7.Use the following declarations and initializations to evaluate the Java expressions: (Please note that each expression has been tested separately.) int i=3, j=7, k=11; j * k++ /2


8.Consider the following statements on global data: #155. Consider the following statements on global data: Global data (i) can be accessed by a number of procedures. (ii) is defined within an outer procedure and may then be shared by the inner procedure. (iii) encourages the need to pass the data from one procedure to another. (iv) causes inconsistencies when shared by procedures. Choose the incorrect statement from among the above.

Only (i) is incorrect
Both (i) and (ii) are incorrect
Only (ii) is incorrect
Both (iii) and (iv) are incorrect
Only (iii) is incorrect.

9.Consider the following program written in Java: class User { private String userName; private int userType; public void setUserName(String s) { this.userName = s; } public void setUserType(int t) { this.userType = t; } public String getUserName() { return userName; } public int getUserType() { return userType; } } public class Main { public static void main(String[] args) { User u = new User(); System.out.println(u.getUserName()); System.out.println(u.getUserType()); } } Which of the following is the output?

null null
null 0
0 null
0 0

10.Consider the following Java program: public class MyClass { private int myVlaue = 5; public void printMyVlaue() { System.out.println(myVlaue); } public void setMyVlaue(int myVlaue) { System.out.println(myVlaue); this.myVlaue = myVlaue; } public static void main(String[] args) { MyClass myClass1 = new MyClass(); myClass1.setMyVlaue(10); myClass1.printMyVlaue(); } } Which of the following will the output be?

5 10
10 10
10 5
5 5
15 5

More Java Programming QUESTIONS AND ANSWERS available in next pages

    Health is the greatest gift, contentment is the greatest wealth -Buddha
If your ship doesn’t come in, swim out to meet it!-Jonathan Winters