Test your Java skill – Beginner level

The beginners level (green level) offers simple and easy Java tests. Its level starts from a beginner programmers to programmers who have less than a year experience with Java.

If the tests are too difficult for you, then I would recommend to click the link under the Exercise title to read my article about that specific Java topic and try again.

test-your-java-skill-beginner_480_324

Test 1: Easy constructors of subclasses and superclasses

Read More: Java Inheritance.

What happens when the following program is compiled and run?

class MySuper {

	protected int b;
}

final class MySub extends MySuper {

	int b = 5;

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

Select the correct answer.



Test 2: Local variables beginners level

Read More: Java Methods.
Read More: Java Classes And Objects.

What happens when the following program is compiled and run?

public class MyClass {

	int b = 4;

	public static void myMethod(int b){
		b ++ ;
		System.out.print("-b" + b);
		b ++ ;
	}
	public static void main(String args[]){
		int b = 2;
		myMethod(b);
	}
}

Select the correct answer.


Test 3: Simple inner classes beginners.

Read More: Java Nested And Inner Classes

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

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

Select the correct answer.


Test 4: Array of an integer.

Read More: Java Arrays

What will happen if you try to compile and execute the main method?

public class MyArray {

	public static void main(String[] args){
		int[] arrayInt = new int[7];
		arrayInt[4] = 3;
		arrayInt[6] = 2;
		for(int i = 0; i < arrayInt.length; i ++ ) { if(i > 2) {
				System.out.print("-x" + arrayInt[i]);
			}
		}
	}
}

Select the correct answer.


Test 5: A simple Java method

Read More: Java Methods.
Read More: Java Constructors

What will happen if you try to compile and execute the main method?

public class MyMethod {

	double x = 12;
	double y = 10;

	public double getResult(double x, double y){
		return this.x + y;
	}
	public static void main(String[] args){
		MyMethod mm = new MyMethod();
		System.out.println(mm.getResult(4,3));
	}
}

Select the correct answer.


Please, leave your questions, feedback and suggestions in the comments below!
SarMaroof.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.


Sar Maroof is graduated from HBO Amsterdam “higher professional education” when he already had a bachelor of science degree in Physics.
He is a SUN certified JSP as well as EJB. He has experience with Java since 2001 and worked for several big as well as small companies and later as a freelancer.
He is the author of Java quizmaster and Build a Java application in 7 days.

Books by Sar Maroof

           
 Subscribe to Sar Maroof's RSS feeds!
 Mail this page to a friend!
 Bookmark this page!
Share on FacebookTweet about this on TwitterShare on RedditShare on LinkedIn

6 Comments

Add a Comment
  1. Hahaha I did better in the intermediate quiz than beginner. Confusion xD

  2. That’s really thinking at an imssrepive level

  3. In the first question, am I correct in saying that the answer, technically, is that main() prints nothing? Technically it is the MySub class object that has the print statement so it isn’t main() that prints anything? Obviously main() instantiates an object, MySub that does the printing? It is the MySub object that writes the answer.
    Great site!

    1. Thanks for your feedback!

      1. Wow, this is in every resepct what I needed to know.

    2. Action requires kngdelwoe, and now I can act!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sarmaroof © 2017