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

SCJP

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

 
Megha's picture

SCJP True False Question Set 1

5
Your rating: None Average: 5 (1 vote)
Q.1 Will this statement compile?

  int i= 1 + '1';

  a. true
b. false


  Q.2 java.util.Set maintains key value pair.
  a. True
b. False
Megha's picture

Which of the following statements are true about a static variable?

3.32143
Your rating: None Average: 3.3 (28 votes)
a. Static variable retain its value between method calls.
b. Value of static variable can’t be changed once assigned.
c. Variable can’t be static, only method can be.
d. Only one static variable is shared among all objects of the class.
Megha's picture

Given the following classes, which of the following statements will compile without error?

0
Your rating: None
  1. interface myInterface{}
  2. class another implements myInterface{}
  3. class Hello{}
  4.  
  5. public class HelloWorld extends Hello{
  6.  
  7.  public static void main(String argv[]){
  8.  
  9.   HelloWorld hw= new HelloWorld();
  10.   Hello h = new Hello();
  11.   Object obj = new Object();
  12.   myInterface mi = new another();
  13.  
  14.      }
  15. }
a. obj = mi;
b. mi=obj;
c. h=hw;
d. hw=h;
Megha's picture

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

0
Your rating: None
  1. public class Demo
  2. {
  3.    int myInt = 1;
  4.    public static void main(String argv[])
  5.    {
  6.        int myInt;
  7.        System.out.println(myInt);
  8.    }
  9. }
a. 1 as output
b. 0 as output
c. Compile time error
d. Run time error
Megha's picture

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

0
Your rating: None
  1. public class Demo
  2. {
  3.    public static void main(String args[])
  4.    {
  5.        Long lng = new Long(113);
  6.        System.out.println(lng);
  7.    }
  8. }
a. Compilation error
b. No compilation error but will throw runtime exception when executed.
c. 113
d. None of the above
Syndicate content