Skip to content

Instantly share code, notes, and snippets.

Avatar
Up and up and up...

Devansh Maurya Devansh-Maurya

Up and up and up...
View GitHub Profile
View multiple_inheritance.java
class A {
//...
}
//class B inherits class A
class B extends A {
//...
}
//class C inherits B, which in turn, inherits A
View final_inheritance.java
final class A {
//...
}
//The following class is illegal
class B extends A { // ERROR! Can't subclass A
//...
}
View finalize.java
protected void finalize() {
//finalization code here
}
@Devansh-Maurya
Devansh-Maurya / final_method.java
Last active Sep 30, 2018
Example showing how final prevents method overriding
View final_method.java
class A {
final void meth() {
System.out.println("This is a final method");
}
}
class B extends A {
void meth() { // ERROR! Can't override.
System.out.println("Illegal!");
}
View EditorActivity.java
Intent intent = getIntent();
currentPetUri = intent.getData();
if (currentPetUri == null) {
setTitle("Add a new pet");
} else {
setTitle("Update pet data");
// Initialize a loader to read the pet data from the database
// and display the current values in the editor
getLoaderManager().initLoader(EXISTING_PET_LOADER, null, this);
View AddPetIntent.java
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);
startActivity(intent);
}
});
View UpdateIntent.java
ListView petListView = findViewById(R.id.list);
petListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);
Uri currentPetUri = ContentUris.withAppendedId("content://com.example.android.myapplication/pets", id);
intent.setData(currentPetUri);
startActivity(intent);
}
View PetUri.java
ContentUris.withAppendedId("content://com.example.android.myapplication/pets", id);