Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Steven's blog

Steven's picture

Whan happens when you compile and run the following code?

5
Your rating: None Average: 5 (2 votes)
  1. public class Q5 {
  2.  public static void main(String args[]){
  3.   int i = 10;
  4.   int j = 12;
  5.   i+=++j;
  6.   System.out.println(i);
  7.  }
  8. }
a. Program will print 13
b. Program will print 23
c. Program will print 22
d. Program will print 12

 
Steven's picture

Priority of thread can not be changed, OS decides which thread to run and when.

3
Your rating: None Average: 3 (2 votes)
Priority of thread can not be changed, OS decides which thread to run and when.

A. True
B. False
  Answer:

B false. Thread priority can be set using setPriority method of Thread class. The way Java schedules thread is platform dependent, so varies from one platform to another.
Steven's picture

What will be the output of following program?

0
Your rating: None
  1. public class Q3{
  2.  
  3.  public static void main(String args[]){
  4.   try{
  5.    Demo d = new Demo();
  6.    d.method1();
  7.    System.out.println("Main Completed");
  8.   }catch(Exception e){}
  9.  }
  10. }
  11.  
  12. class Demo{
  13.  
  14.  public void method2(){
  15.   throw new ArrayIndexOutOfBoundsException();
  16.  }
  17.  
  18.  public void method1(){
  19.   try{
  20.    method2();
  21.   }catch(NullPointerException ae){
  22.    System.out.pri
Steven's picture

What will be output of following program?

0
Your rating: None
  1. public class Q2 {
  2.  static int class_var = 2;
  3.  
  4.  public Q2(){
  5.   class_var = 5;
  6.  }
  7.  public static void main(String args[]){
  8.   System.out.println(class_var);
  9.  }
  10. }
a. 2
b. 5
c. Compile time error
d. None of the above.

 
Steven's picture

What will happen when you compile and run the following code?

0
Your rating: None
  1. public class Q1 {
  2.  public static void main(String args[]){
  3.   int i = 010;
  4.   System.out.println(i);
  5.  }
  6. }
a. Program will give compilation error
b. Program will give runtime error
c. Program will print 8
d. None of the above

 
Syndicate content