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

How to Send OTP in Mobile Number | login with OTP mobile Number | How to send OTP in mobile no with Spring Boot APP

   ðŸ˜‚               Login with Mobile Number OTP ---------------------------------------------------------------------------- If you want to develop a project to log in with OTP mobile Number in Spring Boot Applications then this post for you. In this post, I am going to use some other service to send the OTP in mobile number. we have to use it in this project spring boot. we are going to use Twilio to send SMS. we are going to use a web socket to send the data from the browser to the SMS gateway. Oracle Database for store the user details. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>2.3.3.RELEASE</version> </dependency> <dependency> <groupId>com.twilio.sdk</grou

Spring Boot With MySQL Database connection with Examples | MySQl Database Configuration with Spring Boot Projects

 ðŸ˜ƒ MySQL Database Configuration with Spring Boot Projects  In this article, we are going to introduce How to connect MySQL Database with the Spring Boot project. pom.xml   <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</gro

How can we create Auto generated field or ID for mongodb using spring boot

😂 How can we create an Auto-generated field or ID for MongoDB using spring boot? First Create One Application Like Mongodb_sequence-id-generator Pom.XML <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>de.flapdoodle.embed</groupId> <artifactId>de.flapdoodle.embed.mongo</artifactId> </dependency> User.java package com.app; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; @Document(collection = "users_db") public class User { @Transient public static final String SEQUENCE_NAME = &