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.

JAVA Programming :: Basic Concepts

Home > JAVA Programming > Basic Concepts > General Questions

31. String s = new String("xyz");
Assuming the above declaration, which of the following statements would compilation. Select the one correct answer.

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

32. Which of the following are Java key words?

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option E

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

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

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

34. 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. }

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

Cannot call a non static method from a static method.

Workspace

Tags:

No Tags on this question yet!

35. 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();
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

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!

36. 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._$);
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

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!

37. 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();
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option D

Explanation:

Only public superclass can be accessible for different package.

Workspace

Tags:

No Tags on this question yet!

38. 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);
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

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!

39. 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());
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

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!

40. 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();
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

First execute static block, then statement block then constructor.

Workspace

Tags:

No Tags on this question yet!