JSharp - J# MCQs

JSharp - J# MCQs

These JSharp - J# multiple-choice questions and their answers will help you strengthen your grip on the subject of JSharp - J#. You can prepare for an upcoming exam or job interview with these JSharp - J# MCQs.
So scroll down and start answering.

1: Consider the following program:
import java.util.*;
public class ListColl {
   public static void main(String str[]) {    
     List l = new ArrayList();
     l.add("1");
     l.add("2");
     l.add(1,"3");
     List l2 = new LinkedList(l);
     l.addAll(l2);

     System.out.println(l);    
   }
}

Which of the following sequences will be printed when the above program is run?

A.   [1, 3, 2, 1, 1, 2]

B.   [1, 3, 1, 1, 3, 2]

C.   [1, 1, 2, 1, 3, 2]

D.   [1, 3, 2, 1, 3, 2]  

2: What will be the output when the following code is compiled and run?

class Equates {
     Equates() {
       int a,b,c;
       a = b = c = 20;
       System.out.println(a);
     }
     public static void main(String str[]) {
       new Equates();
     }
}

A.   The code will fail to compile

B.   20 is printed

C.   Nothing is printed

D.   True is printed 

3: What will be the output of the following program?

public class Prnt
{
   public static void main(String args[])
   {
       System.out.println(11 ^ 2);
   }
}

A.   10

B.   9

C.   11

D.   13

E.   121 

4: You have defined a static method to divide two integers:

1        public static int divide(int a,int b) throws Exception
2        {
3                if(b==0)
4                        throw new Exception("Invalid Value for denominator");
5                else
6                        return (a/b);
7        }

Which of the following statements is correct?

A.   The method syntax is correct

B.   The general Exception cannot be specified with parameter (line 4)

C.   In the line 4, the word 'throw' should be replaced with 'throws'

D.   A static method can be throw not as throw Exceptions 

5: What will be the output when the following code is compiled and run?

abstract class Search {
  public Search() { }
  
  public abstract void Result();
}

public class SearchMain extends Search {
  
  public SearchMain() { }
  
  public int Result() {
    System.out.println("I am Result()");
    return 1;
  }

  public static void main(String str[]) {
    new SearchMain().Result();
  }    
}

A.   The code will fail to compile

B.   The code will compile but fails to run

C.   The code will compile and print "I am Result()"

D.   The code will compile but does not produce any output

6: A Student class extends Person class:
1        class Person
2        {
3                 int heightcm;
4
5                Person()
6                {        this.heightcm=160;         }
7        
8                int getHeight()
9                {        return heightcm;          }
10
11                String display()
12                {        return "Person height is " + heightcm; }
13        }

14        class Student extends Person
15        {
16                int studhtcm;
17                String className()
18                {        return "Student";        }
19
20                public static void main(String args[])
21                {
22                        Person obj = new Student();
23                        System.out.println(obj.getHeight());
24                        System.out.println(obj.display());
25                        System.out.println(obj.className());
26                }
27        }

What will happen on compiling and running the code?

A.   The Program will compile and run successfully.

B.   The Program will not compile due to an error in line 23

C.   The Program will not compile due to an error in line 24

D.   The Program will not compile due to an error in line 25 

7: You have created the following class to print some numbers:

public class PrintNumber {
         int a;
         int b;
        
         public void basefunt() {
            a = 0;
            b = 0;
            int[] c = { 0 };
            modify(b, c);
                System.out.println("" + a  + b + c[0]);
         }
    
         public void modify(int b, int[] c) {
            a = 1;
            b = 1;
            c[0] = 1;
         }

          public static void main(String args[]) {
            PrintNumber  p = new PrintNumber();
            p.basefunt();
         }
       }

What will be the output?

A.   000

B.   101

C.   001

D.   110

E.   100

8: Consider the following class:

public class Intro {
        static int a;
        int b;
    
        public Intro() {
            int c;
            c = a;
            a++;
            b += c;
        }

        public void Intro() {
           int c;
            c = a;
            a++;
            b += c;
        }

        public static void main(String args[]) {
           new Intro();
        }
  }

What will happen on compiling and running this class?

A.   The code will fail to compile because there are two constructors with the same names and parameters

B.   The code will fail to compile because the constructor is trying to access a static variable

C.   The code will compile but gives a runtime error

D.   The code will compile and runs successfully 

9: You have defined the following methods in one of the java classes:

1        void setId(int newId)
2        private void manageRecord(int RecordNo)
3        protected void delete(int recordNo)
4        boolean isValidRecord(int recordNo)

Which of the following methods is incorrect for a class that extends above class?

A.   public void setId(int newId)

B.   void manageRecord(int RecordNo)

C.   void delete(int recordNo)

D.   protected boolean isValidRecord(int recordNo)

10: The Tracer and Viewer classes are as follows:
class Tracer {
  public static int traceNo = 10;
}

class Viewer {

     Viewer() {
       Tracer t1 = new Tracer();
       Tracer t2 = new Tracer();
      
       update(t1);
       update(t2);
     }
    
     private void update(Tracer t) {
        t.traceNo = t.traceNo + 1;
        System.out.println(t.traceNo);
     }

     public static void main(String str[]) {
       new Viewer();
     }
}

What will be the result obtained on compiling and running the viewer on .net command prompt?

A.   The code will fail to compile

B.   11 12

C.   11 11

D.   12 12  

11: You created a few classes (as mentioned below) for file manipulation:

public class CopyFile
{        }
class ReadFile
{        }
class WriteFile
{        }

Which of the following is a valid way to name the ".java" file containing the above classes?

A.   ReadFile.java

B.   WriteFile.java

C.   FileManupulation.java

D.   All of the above 

12: You created the class Msg { Msg() { String str1 = "Health"; String str2 = "is"; String str3 = "Wealth"; System.out.println(str1.concat(str2)); str1.concat(str2); System.out.println(str1.concat(str3)); } public static void main(String str[]) { new Msg(); } } What will happen on compiling and running the code? '>

A.   This code will fail to compile because arrayIndexOutOfBound exception is not caught

B.   It will print Healthis on the first line followed by HealthWealth on the second line

C.   It will print Healthis on the first line followed by HealthisWealth on the second line

D.   It will print Healthis on the first line followed by HealthisHealthWealth on the second line 

13: You want a component to resize vertically, but not horizontally. How should it be placed?

A.   BorderLayout in the North or South location

B.   FlowLayout as the first component

C.   BorderLayout in the East or West location

D.   BorderLayout in the Center location

E.   GridLayout 

14: Which of the following is not a correct way of getting "sin" value?

A.   Math m = null;
double val = m.sin(25);

B.   double val = Math.sin(25);

C.   Math m = new Math();
double val = m.sin(25);

15: What will be the output when myMethod() is executed?

class MyPoint {  

  void myMethod() {  
     int x, y;
     x = 5; y = 3;
     System.out.print( " ( " + x + ", " + y + " ) " );
     switchCoords( x, y );
     System.out.print( " ( " + x + ", " + y + " ) " );
  }

  void switchCoords( int x, int y ) {  
     int temp;
     temp = x;
     x = y;
     y = temp;
     System.out.print( " ( " + x + ", " + y + " ) " );
  }
}

A.   (5, 3) (5, 3) (5, 3)

B.   (5, 3) (3, 5) (3, 5)

C.   (5, 3) (3, 5) (5, 3)

D.   No output will be printed

16: A class named MyLoop is defined as follows:
public class MyLoop
{
           public static void main(String args[])
        {
               int counter = 0;
               lbl1: for (int i=10; i<0; i--)
                {
                  int j = 0;
                   lbl2:  while (j < 10)
                        {
                               if (j > i) break lbl2;
                                if (i == j)
                                 {
                           counter++;
                           continue lbl1;
                                }
                           }
                           counter--;
               }
       System.out.println(counter);
           }
}
What will happen when you try to compile and run the program?

A.   The program will fail to compile

B.   The program will compile and produce no output

C.   The program will print 0 as output

D.   The program will print 10 as output 

17: Two functions are defined with the same name in a class:
public boolean isGreater(int no1, int no2)
public boolean isGreater(String st1, String st2)
Which of the following concept does this definition represent?

A.   Abstraction

B.   Overloading

C.   Overriding

D.   EncapsulationÂ