Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Cognizant GenC Next Java Questions 2021-22

GenC Next Java Questions 2022

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

57.14%

Parent Parent Child

Parent Parent Child

20.45%

Parent Child Parent

Parent Child Parent

8.12%

Compilation error

Compilation error

14.29%

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

true true true true true true

true true true true true true

59.41%

true false false true false false

true false false true false false

11.44%

false false true false true false

false false true false true false

8.12%

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

10.86%

abcdcba

abcdcba

7.12%

abcdcbd

abcdcbd

79.03%

Compile time error

Compile time error

3%

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

45.8%

Compile time error

Compile time error

26.72%

Runtime error

Runtime error

20.61%

None of the above

None of the above

6.87%

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

17.07%

Child class

Child class

71.95%

Compile time error

Compile time error

8.13%

No output

No output

2.85%

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.

57.72%

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

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

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

6.1%

constructor can have access modifiers. Hence option (A) is false about constructors in java.

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

5.67%

false true

false true

74.9%

true true

true true

10.53%

false false

false false

8.91%

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

DriverManager, Connection, Statement, and ResultSet

DriverManager, Connection, Statement, and ResultSet

30.71%

DriverManager, Driver, Connection and Statement.

DriverManager, Driver, Connection and Statement.

13.69%

DriverManager, Driver, Connection, Statement, and ResultSet

DriverManager, Driver, Connection, Statement, and ResultSet

51.04%

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

33.74%

null

null

21.54%

Sudhir

Sudhir

39.43%

102

102

5.28%

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.

32.86%

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.

54.93%

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.

7.98%

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

Takes a number ‘no’ and returns the sum of its digits. Hence option (B) is correct.

×

Please login to report

Preparation Material for GenC Next Java Section 2021-22

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.