Lyncy M.

asked • 03/23/21

Display the output of the following Program

1. PROGRAM01.

class Demo{

int value1;

int value2;

Demo(){

value1 = 10;

value2 = 20;

System.out.println("Inside Constructor");

}

public void display(){

System.out.println("Value1 === "+value1);

System.out.println("Value2 === "+value2);

}

public static void main(String args[]){

Demo d1 = new Demo();

d1.display();

}

}


  1. What is the OUTPUT?

2. PROGRAM02.

// A simple constructor.

class MyClass {

int x;

// Following is the constructor

MyClass(int i ) {

x = i;

}

}

public class ConsDemo {

public static void main(String args[]) {

MyClass t1 = new MyClass( 10 );

MyClass t2 = new MyClass( 20 );

System.out.println(t1.x + " " + t2.x);

}

}


  1. What is the OUTPUT?

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.