A silly code!

View previous topic View next topic Go down

Java A silly code!

Post by BIT0102-Mohaimin on 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?
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

Java Re: A silly code!

Post by BIT0107-Toma on 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

_________________________________________________________________
Take it easy, make it easy
avatar
BIT0107-Toma
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 280
Points : 453

View user profile

Back to top Go down

Java Re: A silly code!

Post by BIT0122-Amit on 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

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|
avatar
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Java Re: A silly code!

Post by BIT0107-Toma on 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

_________________________________________________________________
Take it easy, make it easy
avatar
BIT0107-Toma
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 280
Points : 453

View user profile

Back to top Go down

Java Re: A silly code!

Post by BIT0102-Mohaimin on 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.
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

Java Re: A silly code!

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

while i was compiling it in my mind.. i got a nullPointerException.. Sad

_________________________________________________________________
Buddhong shoronogocchami..
dhommong shoronogocchami..
shonghong shoronogocchami..
Jogoter sokol prani.. shukhi hok.
avatar
BIT0104-ANIK
Administrator
Administrator

Course(s) :
  • BIT

Blood Group : O+
Posts : 423
Points : 699

View user profile http://anikstech.blogspot.com

Back to top Go down

Java Re: A silly code!

Post by BIT0112-Rokon on 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.

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Java Re: A silly code!

Post by BIT0130-Shakkhor on 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

_________________________________________________________________
I'm not a driver with drinking problem.
I'm an alcoholic with driving problem.

Blog | বাংলা ব্লগ
avatar
BIT0130-Shakkhor
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 209
Points : 328

View user profile

Back to top Go down

Java Re: A silly code!

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


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