Sunday 21 April 2013

Class -10-



package net.dharmaraj;

import java.util.*;

public class TechnoSample {
public static void main(String args[]) {
Vector col = new Vector();
col.add(new Integer(1));
col.add(new Integer(2));
col.add(new Float(3.2d));
col.add(col.elementAt(0));
System.out.println(col.elementAt(0));
col.setElementAt(col.elementAt(2), 0);// setElementAt(Object,Index)
System.out.println(col);

}
}







Answer:-


1
[3.2, 2, 3.2, 1]

Class -9-


package net.dharmaraj;


import java.util.Date;
public class Example
{
public static void main(String ar[])
{
Date d1=new Date(99,11,31);
Date d2=new Date(99,11,31);
method(d1,d2);
System.out.println("d1 is "+d1 +" \n d2 is"+d2);
}
public static void method(Date d1,Date d2)
{
d2.setYear(100);
d1=d2;
}

}

Class -8-


package net.dharmaraj;

public class TechnoSample {
public static void main(String args[]) {
TechnoSample t = new TechnoSample();
TechnoSample d = new DerivedSample();
d.echoN(d.paramA);

}

int paramA = 9;

void echoN(int n) {
System.out.println("number is in Base " + n);
}
}

class DerivedSample extends TechnoSample {
int paramA = 3;

void echoN(int n) {
System.out.println("number is in Derived " + n);
}
}

Answer :--

number is in Derived 9

Class -7-When executed the following line of code will print System.out.println(-1 * Double.NEGATIVE_INFINITY);

Class -7-When executed the following line of code will print         System.out.println(-1 * Double.NEGATIVE_INFINITY);



package net.dharmaraj;

class dev {
public static void main(String ff[]) {
System.out.println(-1 * Double.NEGATIVE_INFINITY);
}
}



A) -Infinity
B) Infinity
C) NaN
D) -NaN

Class -6-What will happen if you compile/run the folowing lines of code?

Class -6-What will happen if you compile/run the folowing lines of code? 


package net.dharmaraj;

import java.util.*;

public class dev {
public static void main(String[] xyz) {
Vector a = new Vector();

// a.addElement(new Integer(10));
a.addElement(10);

System.out.println(a.elementAt(0));
}

}





   1:  Vector a = new Vector();
    2:
    3:  a.addElement(10);
    4:
    5:  System.out.println(a.elementAt(0));
A) Prints 10.
B) Prints 11.
C) Compilation error at line 3.
D) Prints some garbage.

Class -5-What will be the output when you compile and execute the following program.

Class -5-What will be the output when you compile and execute the following program.


package net.dharmaraj;

public class Base {
private int i;

static public void main(String[] a) {
System.out.println("Value is: " + new Base().i);
}
}




Select most appropriate answer(s).
a) Value is: 0 
b) Compile time error. Can't access the private variable i defined in class Base.
c) Compile time error. Can't make a static reference to nonstatic variable i in class Base.
d) Runtime error. Variable i is uninitialized
e) Compile time error. Variable i is uninitialized
f) None

Class -4-What will be the output when you compile and execute the following program.

Class -4-What will be the output when you compile and execute the following program.


public class Base
{
// private int i;
// private static int i;
// static int i;
static public void main(String[] a)
  {
System.out.println("Value is: " + i);

}




Select most appropriate answer(s).
a) Value is: 0 
b) Compile time error. Can't access the private variable i defined in class Base.
c) Compile time error. Can't make a static reference to nonstatic variable i in class Base.
d) Runtime error. Variable i is uninitialized
e) Compile time error. Variable i is uninitialized
f) None