Skip to content
Related Articles

Related Articles

Java | Constructors | Question 1
  • Last Updated : 28 Nov, 2013

Predict the output?




package main;
class T {
  int t = 20;
}
class Main {
   public static void main(String args[]) {
      T t1 = new T();
      System.out.println(t1.t);
   }
}

(A) 20
(B) 0
(C) Compiler Error


Answer: (A)

Explanation: In Java, member variables can assigned a value with declaration. In C++, only static const variables can be assigned like this.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :