Core Java
search
Ctrlk
Core Java
  • 1) Introduction to Java
  • 2) Features of Java
  • 3) Java setup
  • 4) Object and class
  • 5) Packages
  • 6) Data types
  • 7) More on Primitive Data types
  • --> Java User Input (Scanner)
  • 8) Variables
  • 9) Operators
  • 10) More on Operators
  • 11) Flow Control
  • 12) Arrays
  • 13) Methods
  • 14) Method Overloading
  • Problems OOPs
  • 15) Constructors
  • 16) Static keyword
  • 17) this keyword
  • 18) Access Modifiers
  • 19) Inheritance (is-a relationship)
  • 20) Method Overriding
  • 21) Final Keyword
  • 22) Super Keyword
  • Problems - Inheritance (till super keyword)
  • 23) Abstract Keyword
  • 24) Interfaces
  • 25) Inheritance Pitfalls
  • 26) Class inheritance versus interface inheritance
  • 27) Casting
  • 28) Object-oriented design principles
  • 29) Polymorphism
  • 30) String
  • Challenges
  • Threads
  • JRE JDK JVM
  • Untitled
  • Projects
    • Student Management System
  • Core Java Code - Git repo
    • Git repo URL
    • XML
    • Practice Links
gitbookPowered by GitBook
block-quoteOn this pagechevron-down

Problems - Inheritance (till super keyword)

hashtag
Level 1:

hashtag
Basic single level inheritance

hashtag
1)

LogoJava Inheritance I | HackerRankHackerRankchevron-right

hashtag
2)

LogoJava Inheritance II | HackerRankHackerRankchevron-right

hashtag
3)

LogoLogin : Largest Tech Community | Hackathons, Programming & Coding Challenges | TechGig.comwww.techgig.comchevron-right

hashtag
Multilevel inheritance

hashtag
1)

LogoLogin : Largest Tech Community | Hackathons, Programming & Coding Challenges | TechGig.comwww.techgig.comchevron-right

hashtag
Basic method overriding

hashtag
1)

LogoJava Method Overriding | HackerRankHackerRankchevron-right

hashtag
2)

LogoJava Method Overriding 2 (Super Keyword) | HackerRankHackerRankchevron-right

hashtag
3)

LogoLogin : Largest Tech Community | Hackathons, Programming & Coding Challenges | TechGig.comwww.techgig.comchevron-right

hashtag
Level 2:

hashtag
1) Resolve the compilation error :

hashtag
2) Whats the output ?

hashtag
Output :

hashtag
3) Whats the output ?

hashtag
4) Will it compile ?

hashtag
5) Will it compile ?

hashtag
6) Whats the output ?

hashtag
7) Will it compile ?

Previous22) Super Keywordchevron-leftNext23) Abstract Keywordchevron-right

Last updated 6 years ago

  • Level 1:
  • Basic single level inheritance
  • Multilevel inheritance
  • Basic method overriding
  • Level 2:
  • 1) Resolve the compilation error :
  • 2) Whats the output ?
  • 3) Whats the output ?
  • 4) Will it compile ?
  • 5) Will it compile ?
  • 6) Whats the output ?
  • 7) Will it compile ?
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);
	}
}
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);
	}
}
package com.gs.ilp.corejava.Constructor;

public class Problem2 {
	public static void main(String[] args) {
		new BB(4);
	}
}
AA
BB
BB 4
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
package com.gs.ilp.corejava.Constructor;

public class AAA {
	Object m1() {
		return null;
	}
}
class BBB extends AAA {
	String m1() {
		return null;
	}
}
package com.gs.ilp.corejava.Constructor;

public class AAA {

	void m1() {

	}
}

class BBB extends AAA {

	int m1() {
		return 0;
	}
}
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
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 {

}