Subscribe To MegiSoft RSS Feeds!     Your Browser OR  Google Feedburner

Test Your Java Skill – Intermediate Level

The intermediate level (blue level) offers a bit more complicated Java tests than the beginners level. It is designed for Java programmers with one to two years experience.

If you find the tests too difficult, I would recommend clicking on the link under each test title to read my article about that specific topic and try again.

Choose a level: Beginner  Intermediate  Advanced 

test-your-java-skill-intermediate_480_324

Test 1: Java inheritance

Read More: Java Inheritance.
What happens when the following program is compiled and run?

public class MySuper {

	int x = 1;
	int y = 6;

	MySuper() {
		System.out.print("-x" + x);
		new MySuper(5);
	}
	MySuper(int y) {
		System.out.print("-y" + y);
		x = 4;
	}
}

public class MySub extends MySuper {

	int w = 4;

	MySub(int w) {
		System.out.print("-w" + w);
	}
	public static void main(String[] args){
		MySub mySub = new MySub(2);
	}
}

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!

Test 2: One loop with “if” statement.

Read More: Java Conditional Statements
Read More: Java Iteration (Loop) Statements

What happens when the following program is compiled and run?

public class MyClass {

	public static void main(String[] args){
		int y = 3;
		for(int x = 0; x < 3; x ++ ) {
			System.out.print("-x" + x);
			if(x == 1) {
				System.out.print("-x" + y);
			}
			if(x == 0) {
				int b = x + y;
				System.out.print("-x" + b);
			}
		}
	}
}

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!

Test 3: Instance and local variables

Read More: Java Methods.

What happens when the following program is compiled and run?

public class MyClass {

	int x = 5;
	int y = 7;

	public void myMethod(int x){
		System.out.print("-x" + x);
		x = this.x;
		System.out.print("-x" + x);
	}
	public static void main(String args[]){
		MyClass mc = new MyClass();
		int y = 2;
		mc.myMethod(y);
		System.out.print("-y" + 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!

Test 4: An inner class

Read More: Java Nested And Inner Classes

What happens when you try to compile and run the following program?

class Outer {

	public int a;
	private int b;

	Outer() {
		a = 1;
		b = 4;
		InnerA innerA = new InnerA();
		innerA.methodA();
	}
	class InnerA {
		int a = 4;
		private void methodA(){
			System.out.print("-a" + a + "-b" + b);
		}
	}
	public static void main(String[] args){
		InnerA innerA = new Outer().new InnerA();
	}
}

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!

Test 5: Java methods

Read More: Java Methods.
What happens when the following program is compiled and run?

public class MyClass {

	String x = "x";
	int y = 3;

	MyClass() {
		x = "y";
	}
	void myMethod(int y){
		System.out.print(x + y);
	}
	public int myMethod(int i, int i2){
		return i * i2;
	}
	public static void main(String[] args){
		MyClass m = new MyClass();
		int y = m.myMethod(2,3);
		m.myMethod(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!

Test 6: A combination of a “while” loop with an “if else” statement.

Read More: Java Iteration (Loop) Statements

What happens when the following program is compiled and run?

public class MyLoop {

	void methodA(){
		int x = 0;
		int y = 0;
		while(x < 4) {
			++ x;
			y += 2;
			System.out.print("-x" + x);
			if(y > x) {
				System.out.print("-y" + y);
				y -= 2;
			}else {
				x -- ;
				-- y;
				System.out.print("-x" + x);
				System.out.print("-y" + y);
				break;
			}
		}
	}
	public static void main(String[] args){
		MyLoop myLoop = new MyLoop();
		myLoop.methodA();
	}
}

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..
Choose a level: 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

1 Comment

Add a Comment
  1. Real brain power on diylaps. Thanks for that answer!

Leave a Reply

megisoft © 2016