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

Parent Parent Child

Parent Parent Child

20%

Parent Child Parent

Parent Child Parent

10.06%

Compilation error

Compilation error

14.35%

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

true true true true true true

true true true true true true

56.05%

true false false true false false

true false false true false false

12.79%

false false true false true false

false false true false true false

8.98%

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

abcdcba

abcdcba

9.71%

abcdcbd

abcdcbd

70.29%

Compile time error

Compile time error

5.22%

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

Compile time error

Compile time error

23.83%

Runtime error

Runtime error

19.31%

None of the above

None of the above

8.72%

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

Child class

Child class

67.99%

Compile time error

Compile time error

8.48%

No output

No output

4.5%

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.

50.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.

26.94%

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.

13.38%

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

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

false true

false true

68.28%

true true

true true

12.93%

false false

false false

10%

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

DriverManager, Connection, Statement, and ResultSet

DriverManager, Connection, Statement, and ResultSet

28.13%

DriverManager, Driver, Connection and Statement.

DriverManager, Driver, Connection and Statement.

17.79%

DriverManager, Driver, Connection, Statement, and ResultSet

DriverManager, Driver, Connection, Statement, and ResultSet

49.55%

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

40.29%

null

null

20.86%

Sudhir

Sudhir

35.29%

102

102

3.57%

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

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

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

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.