Skip to main content

Sasken Technology objective Question || Java Written test online

     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

Popular posts from this blog

Generate Documentation for Spring Boot API with swagger and Open API 3

 ðŸ˜‚ How to Generate Documentation for Spring Boot API project Make sure your Project having a swagger or open API 3 Dependency then only you get proper Documentation for your Service. ---------------------------------------------------------------------------- Every method or API above you have to Write Like that then only you get proper Documentation If you do everything in your Application and Run your Application and go to browse and search. . http://localhost:8080/v3/api-docs/ if you want to learn more go with this one.  Open API-3   1. For Return List of Object then you have to use this API operation  @Operation(summary = "This will fetch List of Patient Detailas base on Hospital Name") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Successfully fetch All Patient Details from Database ", content = {  @Content(mediaType = "application/json" ,array = @ArraySchema(schema =@Schema(implementation =PatientDe...

#FibonacciNumberSeries Write a program of Fibonacci Number Series|| Fib...

Fibonacci Number Series ============================================ 0 1 1 2 3 5 8 13............. a=0; b=1; i=2; printf(a,b); while(i<=n){ c=a+b; printf(c); a=b; b=c; i++; } =========================================================================== import java.util.Scanner; class Fibonacci { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=0,b=1,c; System.out.print(a+" "+b); for(int i=2;i

In a new programming language how can store multiple types of data in a single variable OR is it possible how can store multiple types of data in a single variable in programming langauge

In a new programming language how can store multiple types of data in a single variable  OR is it possible how can store multiple types of data in a single variable in a programming language Here In a new programming language how can store multiple types of  data in a single variable   help you make the new  concepts, you are learning a programming  Languages really very important: Ideally Yes. If you create an Array of objects. Then it's possible to store any data type with it as an object is the base class. ArrayList can hold multiple types of data, but array doesn't. Variables Variables can be thought of as ‘containers’ for data. Each variable has to  have a unique name, so that you can refer back to it in the program. By using variables, we can refer to values that have not yet been defined.  For example, we can refer to the speed of the ball in different parts of the  game code, but calculate the ball speed later based on different input...