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

31. Which of the following are Java key words?

Answer: Option E

Explanation:

The only correct options are A and D. In option B, 'S' is capital, it should be small, and option C is incorrect because there is no keyword as 'then' in Java.

 

Workspace


Tags:  No Tags on this question yet!

32. Which of the following keywords indicates a thread is releasing its Object lock?

Answer: Option A

Explanation:

Option A is incorrect, as there is no keyword in Java as release.

Option C is incorrect, as continue keyword has nothing to do with locks.

Option D is incorrect, as notifyAll() method can be used in Java to give the notifications for all waiting threads of a particular object that the required lock is available.

Leaving us with option B, which is the correct option, because if a thread calls wait() method on any object, it immediately releases the lock of that particular object and enters into the waiting state.

Workspace


Tags:  No Tags on this question yet!

33. What is the output for the below code ?

1. public class A {
2. int add(int i, int j){
3. return i+j;
4. }
5.}
6. public class B extends A{
7. public static void main(String argv[]){
8. short s = 9;
9. System.out.println(add(s,6));
10. }
11. }

Answer: Option B

Explanation:

Cannot call a non static method from a static method.

Workspace


Tags:  No Tags on this question yet!

34. What is the output for the below code ?
public class A {
int k;
boolean istrue;
static int p;
public void printValue() {
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
public class Test{
public static void main(String argv[]){
A a = new A();
printValue();
}
}

Answer: Option A

Explanation:

Default value of global and static int variable is zero. Default value of boolean variable is false.
More Info: Remember local variable must be initialized before use.

Workspace


Tags:  No Tags on this question yet!

35. What is the output for the below code ?

public class Test{
int _$;
int $7;
int do;
public static void main(String argv[]){
Test test = new Test();
test.$7=7;
test.do=9;
System.out.println(test.$7);
System.out.println(test.do);
System.out.println(test._$);
}
}

Answer: Option D

Explanation:

You can't use a Java keyword as an identifier. do is a Java keyword.
More Info: $7 is valid identifier. Identifiers must start with a letter, a currency character ($), or underscore ( _ ). Identifiers cannot start with a number.

Workspace


Tags:  No Tags on this question yet!

36. What is the output for the below code ?

package com;
class Animal {
public void printName(){
System.out.println("Animal");
}
}
package exam;
import com.Animal;
public class Cat extends Animal {
public void printName(){
System.out.println("Cat");
}
}
package exam;
import com.Animal;
public class Test {
public static void main(String[] args){
Animal a = new Cat();
printName();
}
}

Answer: Option D

Explanation:

Only public superclass can be accessible for different package.

Workspace


Tags:  No Tags on this question yet!

37. What is the output for the below code ?

public class A {
int i = 10;
public void printValue() {
System.out.println("Value-A");
};
}
public class B extends A{
int i = 12;
public void printValue() {
System.out.print("Value-B");
}
}
public class Test{
public static void main(String argv[]){
A a = new B();
printValue();
System.out.println(i);
}
}

Answer: Option B

Explanation:

If you create object of subclass with reference of super class like ( A a = new B();) then
subclass method and super class variable will be executed.

Workspace


Tags:  No Tags on this question yet!

38. What is the output for the below code ?

public enum Test {
BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);
private int hh;
private int mm;
Test(int hh, int mm) {
assert (hh >= 0 && hh <= 2 : "Illegal hour.";
assert (mm >= 0 && mm <= 59) : "Illegal mins.";
this.hh = hh;
this.mm = mm;
}
public int getHour() {
return hh;
}
public int getMins() {
return mm;
}
public static void main(String args[]){
Test t = new BREAKFAST;
System.out.println(t.getHour() +":"+t.getMins());
}
}

Answer: Option B

Explanation:

As an enum cannot be instantiated using the new operator, the constructors cannot be called explicitly. You have to do like Test t = BREAKFAST;

Workspace


Tags:  No Tags on this question yet!

39. What is the output for the below code?

public class A {
static{System.out.println("static");}
{ System.out.println("block");}
public A(){
System.out.println("A");
}
public static void main(String[] args){
A a = new A();
}

Answer: Option B

Explanation:

First execute static block, then statement block then constructor.

Workspace


Tags:  No Tags on this question yet!

40. What is the output for the below code?

public class Test {
public static void main(String[] args){ int i = 010;
int j = 07;
System.out.println(i);
System.out.println(j);
}
}

Answer: Option A

Explanation:

By placing a zero in front of the number is an integer in octal form. 010 is in octal form so its value is 8.

Workspace


Tags:  No Tags on this question yet!



Most Popular Qs.

Latest MCQ Qs.