5
Q:

main() {

int i;

printf("%d",scanf("%d",&i)); // value 10 is given as input here

}

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

Answer:   A) 1



Explanation:

Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should have been scanned successfully. So number of items read is 1.

Subject: Java
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 1796
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 1938
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 2185
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 1662
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 1813
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 3784
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 1688
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 1794