0% found this document useful (0 votes)
39 views1 page

Data Communication and Networking 1 MIDTERm

The code defines a Person class with a private constructor that initializes the private age field to 24. A main method in the Test class creates a Person object using the private constructor and prints the age field, outputting 24.

Uploaded by

gm22 mermaid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views1 page

Data Communication and Networking 1 MIDTERm

The code defines a Person class with a private constructor that initializes the private age field to 24. A main method in the Test class creates a Person object using the private constructor and prints the age field, outputting 24.

Uploaded by

gm22 mermaid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

What is the output of the following Java code?

class Person 

    private int age; 
    
    private Person() 
    { 
        age = 24; 
    } 

public class Test 

    public static void main(String[] args) 
    { 
        Person p = new Person(); 
        System.out.println(p.age); 
    } 
}

a.
Compilation error

b.
Run Time Error

c.
24

d.
Syntax Error

You might also like