Cognizant GenC Next Java Questions 2025

GenC Next Java Questions 2025

Cognizant GenC Next Java Section is one of the most important section for GenC Next 2025 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.

GenC Next Java
Cognizant GenC Next java question

4 Question

Total Question

GenC Next Java Questions 2022

1 Mark/Question

Marking Scheme

Java Questions for GenC Next

100 minutes(shared)

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

55.42%

Parent Parent Child

Parent Parent Child

20.03%

Parent Child Parent

Parent Child Parent

10.2%

Compilation error

Compilation error

14.36%

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

22.46%

true true true true true true

true true true true true true

55.69%

true false false true false false

true false false true false false

12.57%

false false true false true false

false false true false true false

9.28%

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

14.35%

abcdcba

abcdcba

9.62%

abcdcbd

abcdcbd

70.5%

Compile time error

Compile time error

5.52%

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

48.14%

Compile time error

Compile time error

24.66%

Runtime error

Runtime error

18.75%

None of the above

None of the above

8.45%

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

19.18%

Child class

Child class

67.78%

Compile time error

Compile time error

8.57%

No output

No output

4.47%

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.

51.7%

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.55%

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.

11.89%

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

8.87%

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

8.75%

false true

false true

69.46%

true true

true true

12.29%

false false

false false

9.5%

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.48%

DriverManager, Connection, Statement, and ResultSet

DriverManager, Connection, Statement, and ResultSet

28.46%

DriverManager, Driver, Connection and Statement.

DriverManager, Driver, Connection and Statement.

17.54%

DriverManager, Driver, Connection, Statement, and ResultSet

DriverManager, Driver, Connection, Statement, and ResultSet

49.51%

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”};

39.54%

null

null

21.31%

Sudhir

Sudhir

35.89%

102

102

3.26%

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.

36.56%

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.

47.88%

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.

11.08%

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.

4.48%

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 2025

Below are all the topics mentioned from which you can expect MCQ Questions in Section 2 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 Questions4 Questions
Time Limit100 Mins(shared)
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 15 questions right from the pack of 20 questions in the Code Debugging section to get a higher overall score

What is the difficulty level of Cognizant Genc Next exam?

The GenC Next hiring exam is comparatively 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.