Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.


Please wait...

JAVA Programming :: Basic Concepts

Home > JAVA Programming > Basic Concepts > General Questions

41. What is the output for the below code?

1. public class Test {
2. public static void main(String[] args){
3. byte b = 6;
4. b+=8;
5. System.out.println(b);
6. b = b+7;
7. System.out.println(b);
8. }
9. }

Answer: Option C

Explanation:

int or smaller expressions always resulting in an int. So compiler complain about Type mismatch: cannot convert from int to byte for b = b+7; But b += 7;
because +=, -=, *=, and /= will all put in an implicit cast. b += 7 is same as b = (byte)b+7.

Workspace


Tags:  No Tags on this question yet!

42. What is the output for the below code?

public class Test {
public static void main(String[] args){
String value = "abc";
changeValue(value);
System.out.println(value);
}
public static void changeValue(String {
a = "xyz";
}
}

Answer: Option A

Explanation:

Java pass reference as value. passing the object reference, and not the actual object itself. The parameter is essentially a local variable.

Workspace


Tags:  No Tags on this question yet!

43. What is the output for the below code?

public class Test {
public static void printValue(int i, int j, int k){
System.out.println("int");
}
public static void printValue(byte...b){
System.out.println("long");
}
public static void main(String... args) {
byte b = 9;
printValue(b,b,b);
}
}

Answer: Option B

Explanation:

Primitive widening uses the smallest method argument possible.

Workspace


Tags:  No Tags on this question yet!

44. You have a java file name Test.java inside src folder of javaproject directory.
You have also classes folder inside javaproject directory.
you have issued below command from command prompt.
cd javaproject
Which of the below command puts Test.class file inside classes folder ?

Answer: Option A

Explanation:

The -d option lets you tell the compiler in which directory to put the .class file it generates (d for destination)

Workspace


Tags:  No Tags on this question yet!

45. What is the result of compiling and running the following program.
public class test {
public static void main(String args[]) {
String str1="abc";
String str2="def";
String str3=str1.concat(str2);
str1.concat(str2);
System.out.println(str1);
}
}

Answer: Option A

Explanation:

The output is abc, because the content of str1 is "abc".

Don't get confused by line no. 6 i.e, str1.concat(str2);

We are concatinating str1 with str2, but the resultant string having the content as "abcdef" has no reference. It's definitely not that str1 refers to "abcdef"

Workspace


Tags:  No Tags on this question yet!

46. What is the Output o the below code:

public class Base {
public void method(int i) {
System.out.println("Base class Value is" + i);
}
}
public class Sub extends Base {
public void method(int j) {
System.out.println("Sub class Value is" + j);
}

public static void main(String args[]) {
Base b1 = new Base();
Base b2 = new Sub();
b1.method(5);
b2.method(6);
}
}

Answer: Option B

Explanation:

In line no. 11 i.e, Base b1=new Base(); we have created an object of Base class and it's reference is also of Base class. In such a case when b1.method(5); is invoked, Base class method is invoked and we gets an output as Base class value is 5.

On the other hand, line no. 12 i.e, Base b2=new Sub(); we have created an object of Sub class but it's reference is of Base class. In such a case when b2.method(6); is invoked, Sub class method gets invoked, and we get the output as Sub class value is 6.  

Workspace


Tags:  No Tags on this question yet!

47. Which of these classes defined in javio and used for file-handling are abstract. Select the two correct answers.

Answer: Option A

Explanation:

The correct option is InputStream and Reader, which are defined in java.io package and are used for file handling. 

Workspace


Tags:  No Tags on this question yet!

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace


Tags:  No Tags on this question yet!

49. What is the output of the below code:

public class Example {
int x = 50;
int y = 100;
public static void main(String args[]) {
int x = 0, y = 10;
Example ex = new Example();
while(x < {
x++; y--;
}
System.out.println("X = "+x+",Y ="+y);
}
}

Answer: Option B

Explanation:

x = 3, y = 7

Workspace


Tags:  No Tags on this question yet!

50. Find the Output:

String valid = "true";
if(valid)
System.out.println("valid");
else
System.out.println("not valid");

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace


Tags:  No Tags on this question yet!



Most Popular Qs.

Latest MCQ Qs.