0
Q:

What is the output of this program ?

class main_arguments {
            public static void main(String [ ] args)
            {
                String [][] argument = new String[2][2];
                int x;
                argument[0] = args;
                x = argument[0].length;
                for (int y = 0; y < x; y++)
                    System.out.print(" " + argument[0][y]);           
            }
        }

A) 1 1 B) 1 0
C) 1 0 3 D) 1 2 3

Answer:   D) 1 2 3



Explanation:

In argument[0] = args;, the reference variable arg[0], which was referring to an array with two elements, is reassigned to an array (args) with three elements.
Output:
$ javac main_arguments.java
$ java main_arguments
1 2 3

Subject: Java
Exam Prep: GATE
Q:

In a class if private data member is declared then how to get value of that data member?

Answer

By using method.


The method used to get the data is called getter method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1424
Q:

In a class if private data member is declared then how to set data to that private data member?

Answer

By using method.


The method used to set the data is called setter method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1482
Q:

What is the differnce among public, protected and package access data?

Answer

If we are not using packages and if we are not using inheritance then there is no difference among public, protected and package access data.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1610
Q:

When this. non-static datamember is compulsory inside non-static method

Answer

Whenever there is local- variable/parameter inside the method with same name as data member.


Ex:


Class Sample {


 int a;


  void show() {


   int a=5;


   system.out.println(a); // 5


   system.out.println(this.a);//23


  }


}


class MainApp {


  Public static void main(String[] args) {


  Sample s = new Sample();


   s.a = 23;


   s.show();


   }


}


 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1834
Q:

What is stored in the 'this' reference?

Answer

This is a keyword and used as reference to Current object address in java. 


It means by using which object the method is called that object hashcode is stored inside the 'this'.

Report Error

View answer Workspace Report Error Discuss

Subject: Java
Job Role: Analyst

0 1428
Q:

Why static method can not call non static method of the same class?

Answer

bcoz the static method does not contains the 'this' reference.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2373
Q:

How to assign address to the reference?

Answer

ClassName refName = new ClassName();


or


ClassName refName;


refName = new ClassName();

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1453
Q:

What is the syntax to create the object?

Answer

new ClassName();


This expression creates object in heap area and returns that obj address. Here JVM creates object but JVM does not returns object original address. JVM returns duplicate address, duplicate address is also called as hashcode. 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1474