Cognizant GenC Next Java Questions 2023

GenC Next Java Questions 2023

Cognizant GenC Next Java Section is one of the most important section for GenC next 2023 hiring. This section will assess your technical skills which includes topics such as control structure, Oops, classes/objects, Exceptional Handling, Collection Framework, File Handling, JDBC etc. The topics mentioned in this section will also help you during your interview process.

cognizant genc next java questions 2023
Cognizant GenC Next java question

20 - 25 Question

Total Question

GenC Next Java Questions 2022

1 Mark/Question

Marking Scheme

Java Questions for GenC Next

40 minutes

Total Time

negative marking for genc next java questions

No

Negative Marking

Practice Questions for GenC Next Java Section

1. What will be the output of the following program ?

class Parent
{
    public void display ()
    {
        System.out.println ("Parent");
    } 
} 

class Child extends Parent
{
    public void display ()
    {
        System.out.println ("Child");
    } 
} 
class Main
{
  
    public static void doDisplay (Parent p)
    {
        p.display ();
    }
    
    public static void main (String[]args)
    {
        Parent a = new Parent ();
        Parent b = new Child ();
        Child c = new Child ();
        doDisplay (a);
        doDisplay (b);
        doDisplay (c);
    } 
}

 

Parent Child Child

Parent Child Child

54.33%

Parent Parent Child

Parent Parent Child

20.72%

Parent Child Parent

Parent Child Parent

10.06%

Compilation error

Compilation error

14.89%

Display method in child class is overridden, so method resolution is based on the object.Hence the answer is Parent Child Child.

2. What will be the output of the following program ?

class StringDemo 
{
    public static void main (String[]args) 
    {
        String s1 = new String ("This is prepinsta Material");
        String s2 = new String ("This is prepinsta Material");
        System.out.println (s1 == s2);
        String s3 = "This is prepinsta Material";
        System.out.println (s1 == s3);
        String s4 = "This is prepinsta Material";
        System.out.println (s3 == s4);      
        String s5 = "This is ";
        String s6 = s5 + "prepinsta Material";
        System.out.println (s3 == s6);
        final String s7 = "This is ";
        String s8 = s7 + "prepinsta Material";
        System.out.println (s3 == s8);
        System.out.println (s5 == s7);
    } 
}

false false true false true true

false false true false true true

21.23%

true true true true true true

true true true true true true

56.13%

true false false true false false

true false false true false false

13.92%

false false true false true false

false false true false true false

8.73%

The object which is created by a new keyword is always created in the heap area. The object created with string literal is always created in string constant pool and if the object is already existing then it will not create a new object. Hence the object which is created with string literal returns true and the object which is created with new keyword returns false on their comparison.
Hence the output is option (A).

3. What will be the output of the following program?

class Solution 
{   
    public static void main (String[]args) 
    {
        StringBuffer sb = new StringBuffer ("abcdcbd");
        sb = sb.reverse ();
        sb.setCharAt (0, 'a');
        sb.setCharAt (6, 'd');
        System.out.println (sb);
    } 
}

dbcdcba

dbcdcba

13.66%

abcdcba

abcdcba

8.05%

abcdcbd

abcdcbd

73.41%

Compile time error

Compile time error

4.88%

At first reverse function will reverse the string “abcdcbd” to “dbcdcba” and then setCharAt() function set the character a and d at 0th and 6th position respectively.So At the end we will get our original string as “abcdcbd”. Hence the option C is the correct.

 

4. What will be the output of the following program?

public class Main extends Thread implements Runnable 
{
    public void run () 
    {
        System.out.println ("Prepinsta");
    }
    
    public static void main (String[]args) throws InterruptedException 
    {
        Main obj = new Main ();
        obj.start ();
        obj.run ();
    } 
}

Prepinsta Prepinsta

Prepinsta Prepinsta

46.97%

Compile time error

Compile time error

25.25%

Runtime error

Runtime error

20.45%

None of the above

None of the above

7.32%

Test class extends Thread class that has start() method implemented. So invoking start() on an object that extends Thread class invokes run() method defined in the program.

5. What will be the output of the following program ?

class Sample 
{
    protected void display () 
    {
        System.out.println ("Parent class");
    } 
} 
public class Main extends Sample 
{
    protected void display () 
    {
        System.out.println ("Child class");
    } 
 
    public static void main (String[]args) throws InterruptedException 
    {
        Sample obj = new Main ();
        obj.display ();
    } 
}

Parent class

Parent class

16.39%

Child class

Child class

72.4%

Compile time error

Compile time error

7.92%

No output

No output

3.28%

In case of overriding the method resolution is based on object type. Here in the above question, the object is of type Main therefore the display method present inside main class will get executed.Hence the output is “Child class”.

6. Which of the following is false about constructors in java?

A constructor cannot have an access modifier.

A constructor cannot have an access modifier.

54.16%

The default constructor initializes all the instance variables to default values of the data types.

The default constructor initializes all the instance variables to default values of the data types.

27.61%

If you don’t define a constructor for a class, a default parameterless constructor is automatically provided by the compiler.

If you don’t define a constructor for a class, a default parameterless constructor is automatically provided by the compiler.

10.99%

The name of the constructor should be the same as the class name

The name of the constructor should be the same as the class name

7.24%

Explanation :

  • A constructor in Java is similar to a method that is invoked when an object of the class is created. Unlike Java methods, a constructor has the same name as that of the class and does not have any return type.
  • Constructor can have access modifiers.
  • There are two types of constructors in Java: no-arg constructor, and parameterized constructor.

7. What will be the output of the following java code?

public class Main 
{
    public static void main (String[]args) 
    {
        String s1 = "prepinsta";
        String s2 = new String ("prepinsta");

        System.out.println (s1 == s2);
        System.out.println (s1.equals (s2));
    } 
}

true false

true false

7.07%

false true

false true

72.01%

true true

true true

11.68%

false false

false false

9.24%

Equals method is overridden inside the string class for content comparison whereas == operator compares the reference of the string. Therefore option B is correct.

8. What are the major components of the JDBC?

DriverManager, Statement, and ResultSet

DriverManager, Statement, and ResultSet

4.51%

DriverManager, Connection, Statement, and ResultSet

DriverManager, Connection, Statement, and ResultSet

29.86%

DriverManager, Driver, Connection and Statement.

DriverManager, Driver, Connection and Statement.

15.77%

DriverManager, Driver, Connection, Statement, and ResultSet

DriverManager, Driver, Connection, Statement, and ResultSet

49.86%

Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is a Java-based data access technology used for Java database connectivity.

The major components of jdbc are DriverManager, Driver, Connection, Statement, and ResultSet.

9. What will be the output of the following program ?

public class Main 
{
    public static void main (String[]args) 
    {
        Map < integer, String > student = new HashMap < Integer, String > ();
        
        student.put (101, "Rahit");
        student.put (102, "Sudhir");
        student.put (103, "Adithya");
        student.put (104, "Sakshi");
        System.out.println (student.remove (102));
    } 
}

{101=”Rahit”,103=”Adithya”,104=”sakshi”};

{101=”Rahit”,103=”Adithya”,104=”sakshi”};

38.55%

null

null

20.95%

Sudhir

Sudhir

36.03%

102

102

4.47%

If we remove the element from map it will return the value present at that key.Since in our case value present at 102 is sudhir. Therefore Sudhir will return and print as an output.

10. What does the following method do?

public static int func (int no) 
{
    Deque < Integer > q = new ArrayDeque < Integer > ();
    while (no > 0)
    {
        q.push (no % 10);
        no = no / 10;
    }
    int result = 0;
    while (q.peek () != null)
        result = result + q.pop ();
    return result;
}

Take a number ‘no’ as input and return the reverse of the number.

Take a number ‘no’ as input and return the reverse of the number.

33.33%

Takes a number ‘no’ as input and returns the sum of its digits.

Takes a number ‘no’ as input and returns the sum of its digits.

51.67%

Take a number ‘no’ as input and return the sum of all its digits divisible by 10.

Take a number ‘no’ as input and return the sum of all its digits divisible by 10.

10%

Take a number ‘no’ as input and return 0 if it is divisible by 10.

Take a number ‘no’ as input and return 0 if it is divisible by 10.

5%

In the given code, we declare a deque and we insert the digits of the given number in reverse order. After inserting all digits of the given number in deque, we take out each value and sum them in the result variable.

So, The given code takes a number ‘no’ and returns the sum of its digits.

×

Please login to report

Preparation Material for GenC Next Java Section 2023

Below are all the topics mentioned from which you can expect MCQ Questions in Section 1 of the hiring test. You will also face questions of java in mcq round as well as in coding round from the below topics.

  • Control structures
  • Classes/objects
  • OOPs
  • DSA-Arrays
  • Trees
  • Searching sorting 
  • Exceptional Handling
  • Utility API(Strings, Date) 
  • Collection Framework
  • Database Connectivity
  • File Handling

GenC Next Java Section Details

Java SectionGenC Next
Number of Questions20 – 25 Questions
Time Limit40 Mins
DifficultyMedium
Negative MarkingNo

FAQs about Cognizant GenC Next

What is the sectional cut off for this Section?

There is no sectional cut-off, however it is mandatory that you get at least 18-20 questions right from the pack of 20-25 questions in the MCQ section to get a higher overall score

What is the difficulty level of Cognizant Genc next exam?

The GenC Next hiring exam is commparatively of higher difficulty level than the normal GenC exam. This hiring process is mainly focused for hiring coding proficient students, hence the package offered of GenC next is also higher than GenC.

What is the package offered for Cognizant Genc next exam?

The package offered for GenC Next candidates is 6.75 LPA

WILL I GET ANY OTHER ROLE IF NOT FOUND SUITABLE FOR GENC NEXT

Yes, you will get GenC Elevate role according to performance in skill based assessment and final interview.

WHAT ARE ALL THE ROUNDS IN COGNIZANT GENC NEXT EXAM?

Skill Based Assessment Followed By Technical /HR interview.