Subscribe To MegiSoft RSS Feeds!     Your Browser OR  Google Feedburner

Intermediate Quizzes – Java Static Methods & Variables

The following Java exercise(s) are designed for intermediate level programmers. If the level is too hard, then I recommend to select an easier one or you might consider reading my article about this topic, which offers a theoretical explanation including more exercises. Read More: Java Static Methods And Variables

Article: Java static methods and variables
Quizzes: Beginner  Intermediate  Advanced 

static-members-blue

Quiz 1: A static method and variable in Java

What appears in the standard output when this program is invoked?

public class MyClass {

	static int x = 3;
	int y;

	MyClass() {
		x ++ ;
		y ++ ;
	}
	static void methodA(int i, int i2){
		x = x + i + i2;
		System.out.print("-x" + x);
	}
	int methodB(int i){
		this.y = y + i;
		return x - y;
	}
	public static void main(String[] args){
		MyClass mc1 = new MyClass();
		MyClass.methodA(3,2);
		MyClass.methodA(1,3);
		MyClass mc2 = new MyClass();
		MyClass.methodA(4,2);

		System.out.print("-x" + mc2.methodB(3) + "-x" + mc1.y);
	}
}

Select the correct answer.



Please, leave your questions, feedback and suggestions in the comments below! If you need more explanation by any of the answers, just let me know to update it for you!

Megisoft.com offers a practical method to learn and improve your Java skills. It avoids unnecessary long boring theoretical explanations, but it uses many exercises and quizzes. The author of Megisoft is Sar Maroof who has more than a decade of experience with web development mainly with Java, MySql, HTML and more..
Article: Java static methods and variables
Quizzes: Beginner  Intermediate  Advanced 

Suggested Articles:


Click Here For Info about: Sar Maroof's New Java Book
Author: Sar Maroof
More than a decade of experience with developing web applications mainly with Java.
Sun Certified JSP as well as EJB
CIW Certified Internet Webmaster - Mind IT
Applied Science in Physics HBO Amsterdam
Bachellor Science in Physics at Basra university.
 Subscribe To Megisoft RSS Feeds! (Your Browser)
 Mail This Page To A Friend!
 Bookmark This Page!
Share on FacebookTweet about this on TwitterShare on RedditShare on LinkedIn

Leave a Reply

megisoft © 2016