2
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:

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 1523
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 1562
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 1697
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 1915
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 1519
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 2452
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 1557
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 1613