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:

why overriding finalize() method?

Answer

If constructor opens the file 


finalize() method closes that file.


 


If constructor opens the connection 


finalize() method closes that connection.


 


To perform finalization operation we must overriding finalize method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1716
Q:

What is the purpose of overriding toString() method?

Answer

we can override tostring() method to return String representation of our object data

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1838
Q:

What is final method?

Answer

Final method is a method defined in the super class with final modifier.


We cannot overriding final method of super class in the sub class.


EX:


 Class Sample {


   final void funOne() {


   }


   void funTwo() {


   }


}


Class Sub extends Sample {


  void funOne() { // overriding is not allowed


  }


  viod funTwo() { //overriding is allowed


  }


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2100
Q:

What is the use of overloading ? or why overloading?

Answer

By using overloading we can add new functionality to the sub class.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1578
Q:

What is the use of overriding?

Answer

- By using method overriding a sub class can change the definition of super class method.


- By using overriding a sub class can modify the functionality of the super class.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1720
Q:

If sub class data member is hiding super class data member then how to access super class data member inside sub class methods?

Answer

use super keyword.


super keyword points immediate super class.


Class Sample {


int a =23;


 }


Class Sub extends Sample { 


 String a = "bablu";


 void show() {


 System.out.println(a); //bablu


 System. out. println(this.a); //bablu


 System. out.println(super.a); //23


}


}


Class Demo {


Public static void main(string[] args) {


sub s = new Sub();


s.show();


}


}


 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 3710
Q:

If super class ref is pointing sub class object then by using super class ref is it possible to call sub class newly defined method?

Answer

yes if the method is ovreriding method


no if the method is not overriding method

Report Error

View answer Workspace Report Error Discuss

Subject: Java

134 1550
Q:

What is the use of super call?

Answer

By using super call we can call super class constructors  from sub class constructors and we can initialize super class private data.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1701