Category: Java Quizzes – Beginner

Exercise Inner Classes In Java

What happens when the following Java program is compiled and run?

Select the correct answer.

class Outer {

	public int a;

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


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


Suggested Articles:


 Subscribe To Megisoft RSS Feeds! (Your Browser)
 Mail This Page To A Friend!
 Bookmark This Page!

Java Inheritance exercise for beginners

What is written to the standard output as the result of executing the following Java statements?

 

class MySuper {

	int a;

	public void mySuperMethod(int a){
		System.out.print("-a" + a);
	}
}

public class MySub extends MySuper {

	public static void main(String[] args){
		MySub mySub = new MySub();
		mySub.mySuperMethod(5);
	}
}

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, let me know to update it.


Suggested Articles:


 Subscribe To Megisoft RSS Feeds! (Your Browser)
 Mail This Page To A Friend!
 Bookmark This Page!

A simple Java two parameter constructor for beginners.

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

class MyClass {

	int a = 2;
	static int b = 4;

	MyClass(int a, int b) {
		System.out.print("-a" + a + "-b" + b);
	}
	public static void main(String[] args){
		MyClass m = new MyClass(5,3);
	}
}

Select the correct answer.


 Subscribe To Megisoft RSS Feeds! (Your Browser)
 Mail This Page To A Friend!
 Bookmark This Page!
SarMaroof © 2015