Sasken Technology objective Question in Naresh IT
===============================================
1.
class Test
{public static void main(String[] args)
{
int a=30;
System.out.println((float)a);
}
}
Ans: 30.0
2.
class Test
{
public static void main(String[] args)
{
int a=30;
System.out.println((Float)a);
}
}
Ans:Compile time error becouse. Compiler
unable to convert int to Float Object
3. What is the return type of the hashCode();
Ans: Acutally hash code Returun type is int
Prototype of hashCode() method is
int hashCode();
It is declear in the Object class
4. What is return type of the toString() method
Ans: Return type of the toString() method is
String object
5. What is Correct Prototype of finalize() method
Ans: finalize method is avilable in the class Object
It is protected void finalize(); method is avilable
6. What is the output of this Question in java
class P{
public static void main(String args[]){
for( ; ;){
System.out.println("Hello");
}
}
}
Ans: Hello print Infinit time
Hint- By default in side the loop statement Compiler will
put the true . it is not going to break so that
It will going on infint time.
7.What is the output of this Question in java
class P{
public static void main(String args[]){
String s1=new String("India");
String s2=new String("India");
String s3="India";
String s4="India";
System.out.println(s1.equals(s3));
System.out.println(s3==s4);
}
}
Ans: true
true
Hint: equals method return true and false. if both Content
and Data are same in the both reference than we will
retuen true if (data in not same than it will give you)
false .
But == operator is work on the Data store in the Refernce
variable.
So variable store in only Address of the object.
8.What is the output of Code
class P{
public static void main(String args[]){
int a=10, b=10;
do{
System.out.println("Hello");
}while(a==b);
}
}
Ans: Hello will print infinit time.
9.Waht is output of this Program
class P{
public static void main(String args[]){
int a=2, b=3,c,d;
c=++b;
d=a++;
c++;
System.out.println("a="+a);//3
System.out.println("b="+b);//4
System.out.println("c="+c);//5
System.out.println("d="+d);//2
}
}
Ans: a=3
b=4
c=5
d=2
10.What is output of this program
11. String and StringBuffer is meutable or imutable
String-- imutable
StringBuffer-- mutable
12.What is the output of thi program
abstract class P1
{
public void m1(){
System.out.println("Hello");
}
public abstract void m2();
}
class P extends P1{
public void m2(){
System.out.println("SubClass");
}
public static void main(String args[]){
P1 p=new P1();
p.m2();
}
}
Ans:: error: P1 is abstract; cannot be instantiated
13. What is the output of this program.
class P
public static void main(String args[]){
int total=0,n,x=1;
while(x<=5){
n=x+x;
total+=n;
x++;
}
System.out.println("Total:"+total);
}
}
Ans:Total:30
14. What is the Marker interface
Ans: Serializable
15. What is the work of the clone() method in java
Ans: Create the Copy of the object in java.
16. In the class multiple method with same name but
Different parameter is called a concept of what
Ans: Method Overloading
17. In Object Oriented programming language Having a
Concept of Method overloading and method overriding
Ans: polymorphism concept in java programming
18. What is output
class P extends Thread{
public static void main(String args[]){
Thread th=new Thread();
th.run();
}
}
Ans:Actually run method is declear in the Runnable
interface or Thread class is Implement this class that why
Thread is also provide the run() method body
So , If you Run no probam but output is not printed anything
on the display.
19. What is the output of this program
class P1
{
public static void m1(){
System.out.println("Parent");
}
}
class P extends P1{
public static void m1(){
System.out.println("Child");
}
public static void main(String args[]){
P1 p=new P1();
p.m1();
}
}
Ans: Parent
20.What is the output of this program
class P1
{
public static void m1(){
System.out.println("Parent");
}
}
class P extends P1{
public void m1(){
System.out.println("Child");
}
public static void main(String args[]){
P1 p=new P1();
p.m1();
}
}
Ans: m1() Cannot be override in the p class
Hint: Static method of parent class cannot be override
also final .same rull follow.
Comments
Post a Comment