# Problems - Inheritance (till super keyword)

## Level 1:

### Basic single level inheritance

#### 1)

{% embed url="<https://www.hackerrank.com/challenges/java-inheritance-1/problem>" %}

#### 2)

{% embed url="<https://www.hackerrank.com/challenges/java-inheritance-2/problem>" %}

#### 3)

{% embed url="<https://www.techgig.com/practice/question/single-inheritance/ejIyeUxtK0h1TG5DYlhpQ3h6ZDE0WWV2QlNreVZoWE42N1BPS3AvOGZzOEFUb2VEV29DWDZpby9MaTVIYVB4Qg==/1>" %}

### Multilevel inheritance

#### 1)

{% embed url="<https://www.techgig.com/practice/question/one-two-three/cjJZV0Rlc2w5K2hlZUxmSHgzdk9XUTgzOWhRZHh6UE16aENJSkFFeFp3NDJ5WGRIYnpZTzBWOXg0YlFlcXMvUQ==/1>" %}

### Basic method overriding

#### 1)

{% embed url="<https://www.hackerrank.com/challenges/java-method-overriding/problem>" %}

#### 2)

{% embed url="<https://www.hackerrank.com/challenges/java-method-overriding-2-super-keyword/problem>" %}

#### 3)

{% embed url="<https://www.techgig.com/practice/question/object-oriented-programming/bXpVZEt2bko0V0hPaHhiRDBsVU1tTnh6d3ZFRnF1cFdwMTRIUVNOVFIwZ0FrRmxHWWt1UDlVRmd1M3NJcERXZw==/1>" %}

## Level 2:

### 1) Resolve the compilation error :

![](/files/-LctQSUCxIH4W_o7k0j9)

```java
package com.gs.ilp.corejava.Constructor;

public class ParentWithCon {
	String mem1;
	String mem2;

	public ParentWithCon(String mem1) {
		this.mem1 = mem1;
	}

	public ParentWithCon(String mem1, String mem2) {
		this.mem1 = mem1;
		this.mem2 = mem2;
	}

}

class ChildWithCon extends ParentWithCon {
	public ChildWithCon(String mem1) {
		super(mem1);
	}

	public ChildWithCon(String mem1, String mem2) {
		super(mem1, mem2);
	}
}
```

### 2) Whats the output ?

```java
package com.gs.ilp.corejava.Constructor;

class AA {

	AA() {
		System.out.println("AA");
	}

	AA(int i) {
		this();
		System.out.println("AA " + i);
	}
}

class BB extends AA {
	BB() {
		System.out.println("BB");
	}

	BB(int i) {
		this();
		System.out.println("BB " + i);
	}
}
```

```java
package com.gs.ilp.corejava.Constructor;

public class Problem2 {
	public static void main(String[] args) {
		new BB(4);
	}
}
```

#### Output :

```
AA
BB
BB 4
```

### 3) Whats the output ?

```java
package com.gs.ilp.corejava.Constructor;

class AA {

	AA(int i) {
		this();
		System.out.println("AA " + i);
	}
}

class BB extends AA {
	BB() {
		System.out.println("BB");
	}

	BB(int i) {
		this();
		System.out.println("BB " + i);
	}
}
```

```
CTE
```

### 4) Will it compile ?

```java
package com.gs.ilp.corejava.Constructor;

public class AAA {
	Object m1() {
		return null;
	}
}
class BBB extends AAA {
	String m1() {
		return null;
	}
}
```

### 5) Will it compile ?

```java
package com.gs.ilp.corejava.Constructor;

public class AAA {

	void m1() {

	}
}

class BBB extends AAA {

	int m1() {
		return 0;
	}
}
```

### 6) Whats the output ?

```java
package com.gs.ilp.corejava.Constructor;

class AAA {

	Object m1() {
		System.out.println("AAA m1");
		return null;
	}

}

class BBB extends AAA {

	String m1() {
		System.out.println("BBB m1");
		return null;
	}
}

public class Test2 {
	public static void main(String[] args) {
		AAA aaa = new AAA();
		aaa.m1();

		BBB bbb = new BBB();
		bbb.m1();

		AAA aba = new BBB();
		aba.m1();
	}
}
```

```
AAA m1
BBB m1
BBB m1
```

### 7) Will it compile ?

```java
package com.gs.ilp.corejava.Constructor;

class Animal {

}

class Dog {

}

class Parent {
	Animal m1() {
		return null;
	}
}

class Child {
	Dog m1() {
		return null;
	}
}

public class Test3 {

}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gyansetu-java.gitbook.io/core-java/problems.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
