Thursday, April 9, 2020

Java output questions set - 10


SET-10

1.class test
{
    public static void main(String args[])
   {
 int[] arr = {1,2,3,4};
 call_array(arr[0], arr);
 System.out.println(arr[0] + "," + arr[1]);     
    }
    static void call_array(int i, int arr[])
    {
 arr[i] = 6;
 i = 5;
   } 
}
(A) 1,2
(B) 5,2
(C) 1,6
(D) 5,6

2.public class test
{
 public static void main(String args[])
  {
  int x;
  x = -3 >> 1;
  x = x >>> 2;
  x = x << 1;
   System.out.println(x);
  }
}
(A) 7
(B) 23
(C) 5
(D) 2147483646

3.public class test {
    public static void main(String args[]) {
    String s1 = "abc";
    String s2 = "abc";
    if(s1 == s2)
        System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }
}

(A) 1 2
(B) 1 3
(C) 1 4
(D) 2 4

4.public class test {
    public static void main(String args[]) {
    String s1 = "abc";
    String s2 = new String("abc");

    if(s1 == s2)
        System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }
}
(A) 1 3
(B) 1 4
(C) 2 3
(D) 2 4

5.public class test
{
 public static void main(String args[])
  {
   int i = -1;
   i = i >> 1;
    System.out.println(i);
 }
}
(A) 255
(B) 128
(C) -1
(D) 1

6. Which of the following are legal array declarations
a.int i[5][];
b.int i[][];
c.int []i[];
d.int i[5][5];
e.int[][] a;
(A) a, d, e
(B) b, c, d
(C) b, c, e
(D) a, c, e

7. Which of the following are valid declarations for the main method
a.public static void main(String args[]);
b.public static void main(String []args);
c.final static public void main (String args[]);
d.public static int main(String args[]);
e.public static abstract void main(String args[]);
(A) a, b, c
(B) b, d, e
(C) a, d, c
(D) a, b, e

8.public class example {
  public static void main(String args[]) {
   int x = 0;
   if(x > 0) x = 1;
   switch(x) {
   case 1: System.out.println(1);
   case 0: System.out.println(0);
   case 2: System.out.println(2);
    break;
   case 3: System.out.println(3);
   default: System.out.println(4);
   break;
   }
  }
 }

A.0
B.1
C.2
D.3
E.4
(A) 1, 0, 2
(B) 3, 4
(C) 0, 2
(D) 1

9.String str;
int fname;
str = "Foolish boy.";
fname = str.indexOf("fool");
(A) 0
(B) 2
(C) -1
(D) 4

10.public class test {
 public static void main(String args[]) {
  byte x = 3;
   x = (byte)~x;
   System.out.println(x);
  }
 }
(A) 0
(B) 3
(C) -4
(D) none of these

Java output questions set - 9


SET-9

1)import java.util.*;
class demo1 {
 public static void main(String[] args)
 {
  Vector v = new Vector(20);
  System.out.println(v.capacity());
  System.out.println(v.size());
 }
}
A.20,0
B.22,2
C.20,1
D.20,2
2)
public class testmeth
{
static int i = 1;
public static void main(String args[])
{
System.out.println(i+” , “);
m(i);
System.out.println(i);
}
public void m(int i)
{
i += 2;
}
}

A.1 , 3
B.3 , 1
C.1 , 1
D.1 , 0

3)
Among these expressions, which is(are) of type String?

(A) “0”
(B) “ab” + “cd”
(C) ‘0’
(D) Both (A) and (B) above
(E) (A), (B) and (C) above.
4)
class eq
{
public static void main(String args[])
{
String s1 = “Hello”;
String s2 = new String(s1);
System.out.println(s1==s2);
}
}


(A) true
(B) false
(C) 0
(D) 1
5)
 Use the following declaration and initialization to evaluate the Java expressions

int a = 2, b = 3, c = 4, d = 5;
float k = 4.3f;

System.out.println( – -b * a + c *d – -);

(A) 21
(B) 24
(C) 28
(D) 26
(E) 22.
6)
class prob1{
int puzzel(int n){

int result;

if (n==1)
return 1;
result = puzzel(n-1) * n;
return result;
}
}

class prob2{

public static void main(String args[])

{

prob1 f = new prob1();

System.out.println(” puzzel of 6 is = ” + f.puzzel(6));

}
}
(A) 6
(B) 120
(C) 30
(D) 720
7)
In Java, a try block should immediately be followed by one or more ……………….. blocks.

(A) Throw
(B) Run
(C) Exit
(D) Catch
8)
public class Compute {

public static void main (string args [ ])
{
int result, x ;
x = 1 ;
result = 0;
while (x < = 10) {
if (x%2 == 0) result + = x ;
+ + x ;
}
System.out.println(result) ;
}
}

(A) 55
(B) 30
(C) 25
(D) 35
9)
Which of the following statements about Java Threads is correct?

(A) Java threads don’t allow parts of a program to be executed in parallel
(B) Java is a single-threaded language
(C) Java’s garbage collector runs as a high priority thread
(D) Ready, running and sleeping are three states that a thread can be in during its life cycle

10)
In a class definition, the special method provided to be called to create an instance of that class is known as a/an

(A) Interpreter
(B) Destructor
(C) Constructor
(D) Object 



Java Output questions set - 8


SET-8

1)public class Application {
    public static void main(String[] args) {
       
        String one = "Hello";
        String two = "Hello";
       
        if(one == two) {
            System.out.println("one == two");
        }
        else {
            System.out.println("one != two");
        }
    }
}

A.one == two
B.one != two
C.compile error
D.runtime error

2)Does the following code compile or not?

interface IFruit
{
    public String TYPE = "Apple";
}

class Fruit implements IFruit
{

}

public class Application {
    public static void main(String[] args) {
        System.out.println(Fruit.TYPE);
    }
}
A.yes
B.no
3)
public class HelloWorld{
    public static void main(String[] args) {
        System.out.println(Math.min(Double.MIN_VALUE, 0.0d));
    }
}
A.0.0
B.0.00001
C.Compile error
D.run error
4)
import java.util.*;
public class Test {
    public static void main(String[] args) throws Exception {
        char[] chars = new char[] {'\u0097'};
        String str = new String(chars);
        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));
    }
}
A.-62, -105
B.0097
C.compile error
D.run error
5)
public class FizzBuzzTest{

    public static void main(String args[]){
   
        for(int i = 1; i <=10; i++) {
            if(i % (3*5) == 0) System.out.println("FizzBuzz");
            else if(i % 5 == 0) System.out.println("Buzz");
            else if(i % 3 == 0) System.out.println("Fizz");
            else System.out.println(i);
        }
    }

}

A.1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz
B.Fizz Buzz Fizz 7 8 Fizz Buzz
C.Fizz Buzz
D.1 2 3 4 5 6 7 8 9 10
6)TRUE OR FALSE

class BuggyBread {
   public static void main(String[] args)
   {
      String s2 = "I am unique!";
      String s5 = "I am unique!";
       
      System.out.println(s2 == s5);
   }
}

7)

class BuggyBread2 {

    private static int counter = 0;

    void BuggyBread2() {
        counter = 5;
    }

    BuggyBread2(int x){
        counter = x;
    }
   
    public static void main(String[] args) {
        BuggyBread2 bg = new BuggyBread2();
        System.out.println(counter);
    }
}
A.Compile error
B.Run error
C.5
D.null
8)
public class Test {
 public static void main(String[] args) {
  foo(null);
 }
 public static void foo(Object o) {
  System.out.println("Object impl");
 }
 public static void foo(String s) {
  System.out.println("String impl");
 }
}
A.String impl
B.Object imple
C.compile error
D.run error
9)
long longWithL = 1000*60*60*24*365L;
long longWithoutL = 1000*60*60*24*365;
System.out.println(longWithL);
System.out.println(longWithoutL);
A.31536000000,1471228928
B.12324,56677
C.3153609000,1471228928
D.1245577,324567
10)
public class Testing {
    public static void main(String[] args)
     {
         // the line below this gives an output
         // \u000d System.out.println("comment executed");
     }
}
A.comment executed
B.compile error
C.run error
D.none of the above

Java output questions set - 7


SET-7

1.What is the correct syntax of for each loop?
A.for(variable:collection)
 {body;}
B.for(data_type variable:collection)
 {body;}
C.for(variable;collection)
 {body;}
D.for(data_type variable;collection)
 {body;}

2.public class temp
{
    public static void main(String agrs[])
    {
        for(int i=1; i<=10; i++);
        System.out.print(i);
    }
}
A.12345678910
B.11
C.Error
D.1 2 3 4 5 6 7 8 9 10

3.public class temp
{
    public static void main(String agrs[])
    {
        int i;
        for(i=1; i<=10; i++);
        System.out.print(i);
    }
}
A.12345678910
B.11
C.Error
D.1 2 3 4 5 6 7 8 9 10

4.public class temp
{
    public static void main(String agrs[])
    {
        int x[]={1,2,3,4,5};
        for(int i=0; i<x.length;i++)
            System.out.print(x[i]);
    }
}
A.Error – length is not a method of x.
B.6
C.1,2,3,4,5
D.12345

5.public class temp
{
    public static void main(String agrs[])
    {
        for(int i=1, int j=1; i<5 ; i++, j++)
            System.out.print(i+""+j);
    }
}
A.1122334455
B.12345
C.11223344
D.Error

6.public class temp
{
    public static void main(String agrs[])
    {
       
        for(int i=1, j=1; i<5 ; i++, j++)
            System.out.print(i+""+j);
    }
}
A.1122334455
B.12345
C.11223344
D.Error

7.for(int i=1, j=1; i<5 ; i++, j++)
    System.out.print(i+j);
A.2468
B.12345
C.11223344
D.Error

8.int x = 2;
int y = 8;
while(x<(y+5))
{         
    System.out.println("Hello world!");
    x+=2;
    y-=2;
}
A.3
B.4
C.5
D.6

9.public class temp
{
    public static void main(String agrs[])
    {
        int loop;
       
        for(loop=1; loop<=10; loop++)
        {
            loop*=2;
            if(loop>12)
                break;
        }
        System.out.println(loop);
    }
}
A.11
B.12
C.13
D.14

10.for(int i=10; i<=10; i++)
   {
    System.out.println(i)
   }
A.12345678910
B.11
C.Error
D.1 2 3 4 5 6 7 8 9 10


Java output questions set - 6


SET-6

1)public class A {
    public static void main(String[] args)
    {
        if (true)
            break;
    }
}
a) Nothing
b) Error
2)
public class Example {
    int x = 10;
public static void main(String args[])
    {
        Example obj;
        System.out.println(obj.x);
    }
}
A. 10
B. 0
C. Compile time error
D. Run time error
3)
class TestApp {
    protected int x, y;
}

class Main {
    public static void main(String args[]) {
        TestApp app = new TestApp();
        System.out.println(app.x + " " + app.y);
    }
}
A. 0 1
B. 1 0
C. 0 0
D. null null
4)
class TestApp {
    protected int x, y;
}

class Main {
    public static void main(String args[]) {
        TestApp app = new TestApp();
        System.out.println(app.x + " " + app.y);
    }
}
A. 0 1
B. 1 0
C. 0 0
D. null null
5)
class TestApp {

    public static void main() {
        int odd = 1;
        if (odd) {
            System.out.println("odd");
        } else {
            System.out.println("even");
        }
    }
}
A. odd
B. even
C. Run-time exception
D. Type mismatch error
6)
class TestApp {

    public static void main(String args[]) {
        System.out.println(test());
    }

    static float test() {
        static float x = 0.0;
        return ++x;
    }
}
A. 0.0
B. 1
C. 1.0
D. Compile time error
7)
Command-line: java TestApp 1 2 3 4 5

class TestApp {

    public static void main(String[] args) {

        System.out.println(args[1] + args[2] + args[3]);
    }
}
A. 1 2 3
B. 123
C. 234
D. Compilation Error
8)
import java.io.File;

public class SimpleTest {

    public static void main(String args[]) {
        File sys = new File("/MVC/system");
        System.out.print(sys.getParent());
        System.out.print(" " + sys.isFile());
    }

}
A. MVC true
B. MVC false
C. \MVC false
D. \MVC true
9)
public class SimpleTest {

    public static void main(String ags[]) {
        String initial = "ABCDEFG", after = "";
        after = initial = initial.replace('A', 'Z');
        System.out.println(initial + ", " + after);
    }
}
A. ABCDEFG, ABCDEFG
B. ABCDEFG, ZBCDEFG
C. ZBCDEFG, ABCDEFG
D. ZBCDEFG, ZBCDEFG
10)
public class SimpleTest {

    public static void main(String[] args) {
        int[] table = { 1, 2, 3, 4, 5 };
        table[1] = (table[2 * 1] == 2 - args.length) ? table[3] : 99;
        System.out.println(table[1]);
    }
}
A. Compilation fails.
B. 3
C. 2
D. 99


Java Output Questions set - 5


SET-5
1.if(true && false && true || false)
    System.out.println("True.");
else
    System.out.println("False");
A.True.
B.False.

2.public class temp
{
    public static void main(String args[])
    {
        int ok=10;
        switch(ok)
        {
            default:
                System.out.println("default");
            case 0:
                System.out.println("true");
            case 1:
                System.out.println("false");
        }
    }
}
A.default
B.Error
C.true false default
D.default true false

3.public class temp
{
    public static void main(String args[])
    {
        int x=1;     
        if((boolean)x==true)
            System.out.println("True.");
        else
            System.out.println("False.");
       
    }
}
A.True.
B.False.
C.Error

4.public class temp
{
    public static void main(String args[])
    {
        int x=1; 
        if(x)
            System.out.println("True");
        else
            System.out.println("False");
    }
}
A.True
B.False
C.Error

5.public class temp
{
    public static void main(String args[])
    {
        boolean ok=true;
        switch(ok)
        {
            case true:
                System.out.println("true");
            break;
            case false:
                System.out.println("false");
            break;
            default:
                System.out.println("default");
            break;
        }     
    }
}
A.Error
B.true
C.false
D.default

6.double x = 6.2;
if(x-- >= 6.0)
    System.out.print("first ");
   
if(--x >= 5.0)
    System.out.print("second ");

if(x-- >= 4.0)
    System.out.print("third ");
else
    System.out.print("fourth ");
A.first second third
B.first second fourth
C.first fourth
D.first third

7.public class temp
{
    public static void main(String args[])
    {
        int x=10;
        System.out.println( ((x=5)?"yes":"no") );
    }
}
A.yes
B.no
C.Error

8.public class temp
{
    public static void main(String agrs[])
    {
        int x=10;
       
        switch(x)
        {
            case  5:    x+= 5;
            case 10:    x+=10;
            case 15:    x+=15;
            case 20:    x+=20;
        }
        System.out.println(x);
    }
}
A.55
B.45
C.20
D.10

9.After compilation of a Java program which code generated?
A.Executable code (.exe)
B.Assembly code (.asm)
C.Object Code (.obj)
D.Byte Code (.class)

10.Which company started developing Java (as a Green Project)?
A.Microsoft
B.Oracle
C.Apple
D.Sun Microsystem


Python Technical Interview Questions

 1)first non repeating character Malayalam y programming p str = "MalayalaM" a = '\0' for c in str:     if str.index(c) ==...