Exams Attended

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Core Java Interview Questions and Answers

Ques 111. If a variable is declared as private, where may the variable be accessed?

A private variable may only be accessed within the class in which it is declared.

Is it helpful? Add Comment View Comments
 

Ques 112. If a class is declared without any access modifiers, where may the class be accessed?

A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

Is it helpful? Add Comment View Comments
 

Ques 113. What is a native method?

A native method is a method that is implemented in a language other than Java.

Is it helpful? Add Comment View Comments
 

Ques 114. What is reflection?

Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.

Is it helpful? Add Comment View Comments
 

Ques 115. How can you achieve Multiple Inheritance in Java?

interface CanFight { 
	void fight(); 
}      

interface CanSwim { 
	void swim(); 
}      

interface CanFly { 
	void fly();
}
       
class ActionCharacter { 
	public void fight() {}
}       

class Hero extends ActionCharacter implements CanFight, CanSwim, CanFly { 
	public void swim() {}
	public void fly() {}
}
You can even achieve a form of multiple inheritance where you can use the *functionality* of classes rather than just the interface:
interface A { 
	void methodA();
} 

class AImpl implements A { 
	void methodA() { //do stuff }
}
 
interface B { 
	void methodB();
} 

class BImpl implements B { 
	void methodB() { //do stuff }
}
 
class Multiple implements A, B { 
	private A a = new A();
	private B b = new B();
	void methodA() { 
		a.methodA(); 
	}
	void methodB() { 
		b.methodB(); 
	}
}
This completely solves the traditional problems of multiple inheritance in C++ where name clashes occur between multiple base classes. The coder of the derived class will have to explicitly resolve any clashes. Don't you hate people who point out minor typos? Everything in the previous example is correct, except you need to instantiate an AImpl and BImpl. So class Multiple would look like this:
class Multiple implements A, B { 
	private A a = new AImpl();
	private B b = new BImpl();
	void methodA() { 
		a.methodA(); 
	}
	void methodB() { 
		b.methodB(); 
	}
}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2022 WithoutBook