IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A silly code!

+2
BIT0107-Toma
BIT0102-Mohaimin
6 posters

Go down

Java A silly code!

Post by BIT0102-Mohaimin Mon Jan 31, 2011 1:37 am

Note: I am trying to explain a very important thing for new/unexperienced java programmers. Experienced ones are requested not to answer the question I will ask later.

Carefully observe the Java code bellow. Do not run it. Try to compile in your mind!
Code:

class A{
   private B b;
   
   public int   getBValue(){
      return b.getValue();
   }
}

class B{
   private int value;
   
   public B(int value){
      this.value = value;
   }
   
   public int getValue(){
      return value;
   }
}

class Main{
   public static void main(String[] args) {
      A a = new A();
      B b = new B(3/3);
      
      System.out.println(a.getBValue());
   }
}

Again I am telling, do not compile or run it in your PC. Just see the text and tell- what will be the output?
BIT0102-Mohaimin
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

Back to top Go down

Java Re: A silly code!

Post by BIT0107-Toma Mon Jan 31, 2011 1:50 am

According to Mohaimin, if I only think about IITans, only 2nd batch should reply here first.


Last edited by BIT0107-toma on Mon Jan 31, 2011 1:54 am; edited 1 time in total
BIT0107-Toma
BIT0107-Toma
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 280
Points : 453

Back to top Go down

Java Re: A silly code!

Post by BIT0122-Amit Mon Jan 31, 2011 1:53 am

No fair. You are not a 2nd batch Toma :p very very funny

Anyway, nice problem Mohaimin Very Happy Very Happy RPP
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Java Re: A silly code!

Post by BIT0107-Toma Mon Jan 31, 2011 1:58 am

BIT0122-Amit wrote:No fair. You are not a 2nd batch Toma :p very very funny

Right you are Razz Razz Razz
BIT0107-Toma
BIT0107-Toma
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 280
Points : 453

Back to top Go down

Java Re: A silly code!

Post by BIT0102-Mohaimin Mon Jan 31, 2011 2:02 am

BIT0107-toma wrote:According to Mohaimin, if I only think about IITans, only 2nd batch should reply here first.
I did not want to mean anything like that. Anyone who think he/she should answer can answer.
BIT0102-Mohaimin
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

Back to top Go down

Java Re: A silly code!

Post by BIT0104-ANIK Mon Jan 31, 2011 2:55 am

while i was compiling it in my mind.. i got a nullPointerException.. Sad
BIT0104-ANIK
BIT0104-ANIK
Administrator
Administrator

Course(s) :
  • BIT

Blood Group : O+
Posts : 423
Points : 699

http://anikstech.blogspot.com

Back to top Go down

Java Re: A silly code!

Post by BIT0112-Rokon Mon Jan 31, 2011 12:19 pm

Note: to compile this code, you need to be Java compatible. So first get and set Java environment in your mind.

I've compiled it, written in a log file, I think you guys are not interested to view my log. :p


Mohaimin, nice idea. Keep it up.
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

Java Re: A silly code!

Post by BIT0130-Shakkhor Tue Feb 01, 2011 1:11 am

Trying to outsmart a compiler defeats much of the purpose of using one, don't you think? No
BIT0130-Shakkhor
BIT0130-Shakkhor
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 209
Points : 328

Back to top Go down

Java Re: A silly code!

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum